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.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.
if ($customerId > 0) {
$customerId = $customerId;
} else {
$customerId = $this->customerSession->getId();
}
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...
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, "%");
}
}
const handleBoolean = value => {
switch (value) {
case "true":
return true;
case true:
return "true";
case "false":
return false;
case false:
return "false"
default:
return null;
}
}
SELECT CAST(CASE a8900.AllowCloserChanges
WHEN 0
THEN 0
ELSE 1 END AS BIT) AllowCloserChanges
FROM Vision.sub8900.tApplication8900 a8900
WHERE a8900.ApplicationNum = @ApplicationNum
Inheriting others' code in the fun world of corporate development.
http://localhost:52108/Trade/Details/1953452?class=pull-left
$guard = ($vars->a_payment) + (0) * $price;
if ($bless >= $guard) {
$amount = $bless;
}
Why not to write just 1 line?! $amount = max($bless, $vars->a_payment);
function add(input1,input2) {
var number1 = input1.toString();
var number2 = input2.toString();
var numbers1 = new Array();
var numbers2 = new Array();
var size1 = 0;
var size2 = 0;
while(size1 < number1.length) {
var SizeAndNumberToAddToNumbers1Array = 0;
var Number1FromFunctionAddLength = number1.length-size1-1;
SizeAndNumberToAddToNumbers1Array = number1.charAt(size1);
while(Number1FromFunctionAddLength > 0){
SizeAndNumberToAddToNumbers1Array = SizeAndNumberToAddToNumbers1Array + "0";
Number1FromFunctionAddLength = Number1FromFunctionAddLength-1;
}
numbers1.push(SizeAndNumberToAddToNumbers1Array);
size1 = size1 + 1;
}
while(size2 < number2.length) {
var SizeAndNumberToAddToNumbers1Array2 = 0;
var Number1FromFunctionAddLength2 = number2.length-size2-1;
SizeAndNumberToAddToNumbers1Array2 = number2.charAt(size2);
while(Number1FromFunctionAddLength2 > 0){
SizeAndNumberToAddToNumbers1Array2 = SizeAndNumberToAddToNumbers1Array2 + "0";
Number1FromFunctionAddLength2 = Number1FromFunctionAddLength2-1;
}
numbers2.push(SizeAndNumberToAddToNumbers1Array2);
size2 = size2 + 1;
}
var result1 = 0;
var saize1 = 0;
while(saize1 < numbers1.length){
var topush1 = numbers1[saize1];
result1=result1+parseInt(topush1);
saize1 = saize1 + 1;
}
var result2 = 0;
var saize2 = 0;
while(saize2 < numbers2.length){
var topush2 = numbers2[saize2];
result2=result2+parseInt(topush2);
saize2 = saize2 + 1;
}
return result1+result2;
}
advanced and optimized add function better than a + b
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>
def get_verified_infos(request):
try:
# request logic here
return data
except Exception:
logger.error(
'Request to XXX was unsuccessful, '
'Will retry till max recursion! Retrying...'
)
return get_verified_infos(request)
Used for OpenID authentication
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 => { })
}
*/