String.prototype.capitalize=function(){return this.charAt(0).toUpperCase()+this.slice(1);};
String.prototype.followCase=function(b){
if(b==b.toUpperCase()){return this.toUpperCase();}
if(b==b.toLowerCase()){return this.toLowerCase();}
if(b==b.capitalize()){return this.capitalize();}
return this;
};
String.prototype.atRemoveAdd=function(index,n,string){
return this.substring(0,index)+string+this.substring(index+n,this.length);
};
String.prototype.matchIndex=function(re){
var a=[];
while((match=re.exec(this))!==null){
a.push({chars:match[0].length,index:match.index});
}
return a;
};
String.prototype.caseReplace=function(o,n){
for(var s=this,a=this.matchIndex(o),shift=0,i=0;i<a.length;i++){
var c=n.followCase(this.substring(a[i].index,a[i].index+a[i].chars));
s=s.atRemoveAdd(a[i].index+shift,a[i].chars,c);
shift+=c.length-a[i].chars;
}
return s;
};
My code from 2016 for the hall of shame where I realized today that caseReplace could just return this.replace(o,m=>n.followCase(m))
instead.
Public Shared Function CompeleteDateStr(DateStr As String) As String
'MBS 96-09-25: High Caliber DataEntry
Dim DateVal = CType(DateStr, Integer)
If DateVal < 1 Then Return ""
If DateVal < maxDay Then 'DayOnly
Return MakeJalaliDate(curYear, curMonth, DateVal, _4DigitYear)
ElseIf DateVal > maxDay Then
Dim YearPiece? As Short = Nothing, MonthPiece? As Byte = Nothing, DayPiece As Byte
Select Case DateVal
Case Is < 100
MonthPiece = (DateVal \ 10) Mod 10
DayPiece = DateVal Mod 10
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
Case Is < 1000
MonthPiece = DateVal \ 10
DayPiece = DateVal Mod 10
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
MonthPiece = (DateVal \ 100) Mod 10
DayPiece = DateVal Mod 100
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
DayPiece = DateVal \ 10
MonthPiece = DateVal Mod 10
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
DayPiece = (DateVal \ 100) Mod 10
MonthPiece = DateVal Mod 100
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
Case Is < 10000
MonthPiece = DateVal \ 100
DayPiece = DateVal Mod 100
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
MonthPiece = DateVal Mod 100
DayPiece = DateVal \ 100
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
DayPiece = DateVal \ 100
MonthPiece = DateVal Mod 100
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
DayPiece = DateVal Mod 100
MonthPiece = DateVal \ 100
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
MonthPiece = (DateVal \ 10) Mod 10
YearPiece = DateVal \ 100
If IsValidMonth(MonthPiece) Then
DayPiece = DateVal Mod 10
If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece, _4DigitYear)
Else
MonthPiece = (DateVal \ 100) Mod 10
YearPiece = DateVal Mod 100
DayPiece = DateVal \ 1000
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece, _4DigitYear)
End If
Case Is < 100000
Dim DaySize As Byte = 2
MonthPiece = (DateVal Mod 1000) \ 10
If Not IsValidMonth(MonthPiece) Then
MonthPiece = (DateVal \ 100) Mod 10
DaySize = 1
If Not IsValidMonth(MonthPiece) Then Return ""
End If
YearPiece = DateVal \ 1000
DayPiece = DateVal Mod 10 ^ DaySize
If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece)
YearPiece = DateVal Mod 100
DayPiece = DateVal \ (10000 \ (10 ^ DaySize))
If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece)
Case Is < 1000000
MonthPiece = (DateVal Mod 10000) \ 100
If IsValidMonth(MonthPiece) Then
YearPiece = DateVal \ 10000
DayPiece = DateVal Mod 100
If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece, _4DigitYear)
YearPiece = DateVal Mod 100
DayPiece = DateVal \ 10000
If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece, _4DigitYear)
End If
YearPiece = DateVal \ 100
If YearPiece > 1300 AndAlso YearPiece < 1500 Then
MonthPiece = (DateVal \ 10) Mod 10
DayPiece = DateVal Mod 10
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece, _4DigitYear)
End If
YearPiece = DateVal Mod 10000
If YearPiece > 1300 AndAlso YearPiece < 1400 Then
DayPiece = DateVal \ 100000
MonthPiece = (DateVal \ 10000) Mod 10
If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece + If(_4DigitYear, 0, -1300), MonthPiece, DayPiece, _4DigitYear)
End If
Case Is < 10000000
Dim DaySize As Byte = 2
MonthPiece = (DateVal Mod 1000) \ 10
If Not IsValidMonth(MonthPiece) Then
MonthPiece = (DateVal \ 100) Mod 10
DaySize = 2
If Not IsValidMonth(MonthPiece) Then Return ""
End If
YearPiece = DateVal \ 1000
DayPiece = DateVal Mod 10 ^ DaySize
If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece)
YearPiece = DateVal Mod 10000
DayPiece = DateVal \ (100000 * (10 ^ DaySize))
If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece)
Case Is < 100000000
MonthPiece = (DateVal Mod 10000) \ 100 '13961229
If IsValidMonth(MonthPiece) Then
YearPiece = DateVal \ 10000
DayPiece = DateVal Mod 100
If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece, _4DigitYear)
YearPiece = DateVal Mod 10000
DayPiece = DateVal \ 1000000
If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece, _4DigitYear)
End If
End Select
Return ""
End If
End Function
this code is so wrong in so many different levels
if((strtotime(date("Y-m-d"))-strtotime(date("Y-m-d", filemtime($filename))))/(3600)<=$config->hourDiff) return true; else return false;
please notice the brackets around 3600
for (int i = 0;i < n / 2;i++)
{
while (num[a[p].id].n == 0 || num[num[a[p].id].nxt].n == 0)
{
p++;
}
printf("%d %d ", num[a[p].id].n, num[num[a[p].id].nxt].n);
num[a[p].id].n = 0;
num[num[a[p].id].nxt].n = 0;
num[num[a[p].id].lst].nxt = num[num[a[p].id].nxt].nxt;
num[num[num[a[p].id].nxt].nxt].lst = num[a[p].id].lst;
}
<Image source={ this.props.pickupOrDropoff == "pickup"
? i.pickup
? iconBlue
: iconWhite
: i.dropoff
? iconBlue
: iconWhite} style={{
height:this.props.pickupOrDropoff == "pickup"
? i.pickup
? 30
: i.sign === 'D' ? 30 : 35
: i.dropoff
? 30
: i.sign === 'D' ? 30 : 35,
marginRight:10 ,
width: this.props.pickupOrDropoff == "pickup"
? i.pickup
? 40
: 40
: i.dropoff
? 40
: 40
,resizeMode:'contain'}}/>
I love when the code is neat...
func runAnsible(c *cli.Context) {
runAnsibleCmd1(c.String("command"), c.StringSlice("var-file"), c.StringSlice("var"))
}
func runAnsibleCmd1(cmd string, varfiles []string, varstrs []string) {
runAnsibleCmd2(cmd, util.ToVars(varfiles, varstrs))
}
func runAnsibleCmd2(cmd string, vars map[string]interface{}) {
err := exec.SyscallExecute(cmd, vars)
log.Error("Error running ansible command.", "err", err.Error())
}
public static class DecimalHelpers
{
/// <summary>
/// Format a decimal XX.XX to XX,XX%.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string FormatToStringPercentageValue(this decimal value)
{
return value.ToString().Replace(".", ",").FormatToPercentageValue();
}
}
public static class StringHelpers
{
/// <summary>
/// Add % at the end of the string.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string FormatToPercentageValue(this string value)
{
return string.Concat(value, "%");
}
}
try
{
len = readBufferSize(reader);
}
catch (IOException xcp)
{
throw xcp;
}
I swear I didn't omit a single symbol (except for tabs at the beginning)
filterForProvincia() {
console.log('ciao');
}
The last line of code of a parting Developer
int true = 0;
while (true)
{
//do something
}
true = false
val weekEnd = DateTime.now.withDayOfWeek(5).plusDays(2)
Native XML structure:
<?xml version="1.0" encoding="utf-8" ?>
<tree>
<node name="root">
<node name="TELEVISIONS">
<node name="TUBE"/>
<node name="LCD"/>
<node name="PLASMA"/>
</node>
<node name="PORTABLE ELECTRONICS">
<node name="MP3 PLAYERS">
<node name="FLASH"/>
</node>
<node name="CD PLAYERS"/>
<node name="2 WAY RADIOS"/>
</node>
</node>
</tree>
Flattened XML structure (example 1):
<tree>
<node key="0">root</node>
<node key="1" parent="0">TELEVISIONS</node>
<node key="2" parent="1">TUBE</node>
<node key="3" parent="1">LCD</node>
<node key="4" parent="1">PLASMA</node>
<node key="5" parent="0">PORTABLE ELECTRONICS</node>
<node key="6" parent="5">MP3 PLAYERS</node>
<node key="7" parent="6">FLASH</node>
<node key="8" parent="5">CD PLAYERS</node>
<node key="9" parent="5">2 WAY RADIOS</node>
</tree>
Flattened XML structure (example 2):
<tree>
<node>
<name>root</name>
<depth>0</depth>
</node>
<node>
<name>TELEVISIONS</name>
<depth>1</depth>
</node>
<node>
<name>TUBE</name>
<depth>2</depth>
</node>
<node>
<name>LCD</name>
<depth>2</depth>
</node>
<node>
<name>PLASMA</name>
<depth>2</depth>
</node>
<node>
<name>PORTABLE ELECTRONICS</name>
<depth>1</depth>
</node>
<node>
<name>MP3 PLAYERS</name>
<depth>2</depth>
</node>
<node>
<name>FLASH</name>
<depth>3</depth>
</node>
<node>
<name>CD PLAYERS</name>
<depth>2</depth>
</node>
<node>
<name>2 WAY RADIOS</name>
<depth>2</depth>
</node>
</tree>
if (model.env.Trim().ToUpper() == "Release")
{
retVal = false;
if (!string.IsNullOrEmpty(model.Server_Core))
{
// Perform a trim in case user specified just whitespace...
string tmpStr = model.Server_Core.Trim();
if (!string.IsNullOrEmpty(tmpStr))
{
retVal = true;
}
}
}
string month = DateTime.Today.Month.ToString();
if (DateTime.Today.Month < 10)
{
month = "0" + month;
}
string day = DateTime.Today.Day.ToString();
if (DateTime.Today.Day < 10)
{
day = "0" + day;
}
string dateCorrect = String.Format("{0}.{1}.{2}", DateTime.Today.Year, month, day);
string dateDue = "";
if (transferFields.DueDate.SelectedDate.HasValue)
{
var dateDuearr = transferFields.DueDate.Value.Split(' ')[0].Split('.');
dateDue = dateDuearr[2] + '.' + dateDuearr[1] + '.' + dateDuearr[0];
}
else {
dateDue = dateCorrect;
}
Real developers don't use built in parsing and formatting methods.
ngOnInit() {
this._FunctionService.getSicksList().then(res => {
let resf:any = res;
if (resf.err) {
} else {
this.diagnosticAll = resf.data
}
}, err => { })
}
/*
ngOnInit() {
this._FunctionService.getSicksList().then(res => {
this.diagnosticAll = res.data
}, err => { })
}
*/