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.
function isEmpty(value) {
if (value === '') {
return false;
} else if (value === 0) {
return false;
} else if (value === null) {
return false;
} else if (value === undefined) {
return false;
} else {
return true;
}
return true;
}
javascript empty value check
int w = 100;
for (nil; w!=0; nil) {
w -= 1;
//so some shit
}
this code was found in chinese contract work
private static final double RESULT_OF_DIVISION_BY_0 = 9.99;
public static double getPercentageDifference(long currentResult, long previousResult) {
if (previousResult == 0 && currentResult == 0) {
return 0;
} else if (previousResult == 0) {
return RESULT_OF_DIVISION_BY_0;
} else {
return (currentResult - previousResult) * 1.0 / previousResult;
}
}
if ($customerId > 0) {
$customerId = $customerId;
} else {
$customerId = $this->customerSession->getId();
}
if(computedDate != null){
myObject.setDueDate(computedDate);
}
else{
myObject.setDueDate(null);
}
/**
* fk--folder key,dk--doc key -->value is key string
* dt--doc type,ft--folder type -->both have 19 key options:
* bom tr amend history help info loeid cust cust0-cust9 custhist
* folder type only seen as "history" in toc,why ??do we use other ones? -- it only has one child
* doc type only seen two "tr" and "history" in toc??-- it only has one child
* node with "folder type="history"" is the only child of it parent either "<doc type="tr" key="xxx" trnum="xxx"....." or "<doc type="tr" trnum="xxx""
* <folder type="history" could has more then one doc children .e.g. title="History of AMM31-32-00-720-807" in 700/amm
*
*
*
* folder element has the follwing to identify itself:
* 1, key
* 2, type="history", in this case, folder is the only child of doc element with type ="tr"?????
*
* doc element has the following to identify itself
* 1, key
* 2, type="tr" trnum="xxxxx"
* 3, type="history", in this case, doc isthe only child of a folder element???
*
*
*
* the return json format likes following:
* [
* { "data" : "A node", "children" , "state" : "open" },
* { "data" : "Only child", "state" : "closed" },
* "Ajax node"
* ]
*/
public class XMLToJson
{
private static final Map<String, String> pathMap;
static
{
Map<String, String> aMap = new HashMap<String, String>();
aMap.put("fk", "folder[@key");
aMap.put("ft", "folder[@type");
aMap.put("fth", "folder[@type='history'");
aMap.put("dk", "doc[@key");
aMap.put("dt", "doc[@type");
aMap.put("dth", "doc[@type='history'");
aMap.put("dtrn", "doc[@trnum");
pathMap = Collections.unmodifiableMap(aMap);
}
Util util = new Util();
/*
* @param url the path to TOC.xml
* @param xPathString the short format searched node path
* @throws DocumentException
*
* sample xPathString : "fk:AMM24_fk:AMM24-FM_dk"
*/
@SuppressWarnings({ "unchecked" })
public String getJson(URL url, String xPathString) throws Exception
{
Document TOCDoc = util.getDocument(url);
String jsonString = "[";
Element node = null;
if (xPathString.equals("/"))
{
node = TOCDoc.getRootElement();
}
else
{
String realXPathString = pathMapping(xPathString);
System.out.println(realXPathString);
node = (Element) TOCDoc.selectSingleNode(realXPathString);
}
//List<Element> li = node.elements();
for (Iterator<Element> i = node.elementIterator(); i.hasNext();)
{
Element elem = (Element) i.next();
String eleName = elem.getName();
Boolean hasChildren = false;
if ((elem.elements().size() > 0))
{
hasChildren = true;
//current element has children itself, state shoud be "closed"
}
List<Attribute> list = elem.attributes();
String titleAttrContent = elem.attributeValue("title");
//Boolean isFileAttr = false;
String fileAttrContent = elem.attributeValue("file");
//if (fileAttrContent.isEmpty() )
if (eleName == "doc")
{
//doc element always has "file" attribute
for (Attribute attribute : list)
{
jsonString = jsonString.concat("{");
String attrName = attribute.getName();
//System.out.println("doc arribute Name : " + attrName);
//each one has to have "data" line, "attr" line "state" line and "children" line
jsonString = jsonString.concat("'data':'").concat(titleAttrContent).concat("',");
if (attrName.equals("key"))
{
String keyContent = elem.attributeValue("key");
jsonString = jsonString.concat("'attr':{'id':'").concat(xPathString).concat("_dk:").concat(keyContent).concat("','file':'").concat(fileAttrContent).concat("'}");
break;
}
else if (attrName.equals("trnum"))
{
String trnumContent = elem.attributeValue("trnum");
jsonString = jsonString.concat("'attr':{'id':'").concat(xPathString).concat("_dtrn:").concat(trnumContent).concat("','file':'").concat(fileAttrContent).concat("'}");
break;
}
/* else if (attrName.equals("type"))//type attribute for doc element won't determite what exactly the element is
{
String typeContent = elem.attributeValue("type");
//doc element has type "history"
if (typeContent == "history"){
jsonString = jsonString.concat("'attr':{'id':'").concat(xPathString).concat("_dth,");
}else if (typeContent == "?????"){
//any values for type attribute need to concern????
}
}
else if (attrName.equals("file"))
{
}*/
}
if (hasChildren)
{
//state set up as "closed" and no need to set up "children" field
jsonString = jsonString.concat(",'state':'closed'");
}
else
{
//no need to put anything
//jsonString = jsonString.concat("'state':'???'");
}
jsonString = jsonString.concat("},");
}
else if (eleName == "folder")
{
jsonString = jsonString.concat("{");
for (Attribute attribute : list)
{
String attrName = attribute.getName();
jsonString = jsonString.concat("'data':'").concat(titleAttrContent).concat("',");
if (attrName.equals("key"))
{
String keyContent = elem.attributeValue("key");
jsonString = jsonString.concat("'attr':{'id':'").concat(xPathString).concat("_fk:").concat(keyContent).concat("'}");
if (fileAttrContent != null)
{
jsonString = jsonString.concat("','file':'").concat(fileAttrContent).concat("'}");
}
break;
}
else if (attrName.equals("type"))
{
String typeContent = elem.attributeValue("type");
//doc element has type "history"
if (typeContent == "history")
{
jsonString = jsonString.concat("'attr':{'id':'").concat(xPathString).concat("_fth,");
}
else if (typeContent == "?????")
{
//any values need to concern????
}
break;
}
}
jsonString = jsonString.concat("},");
}
continue;
}
//return list;
jsonString = jsonString.substring(0, jsonString.length() - 1);
jsonString = jsonString.concat("]");
return jsonString;
}
/*
* read xpathstring from post request and generate the real xpath for toc
*/
public String getXPathString()
{
//readPostRequest()
return null;
}
/*
* post string looks like : "fk:LOETR_dtrn:TR12-118_fth_dth"
* it represents the inner doc elemnet:
* <folder key="LOETR" type="loetr" title="List of Effective TRs" file="loetr.html">
* <doc type="tr" trnum="TR12-118" trdate="May 07/2012" title="[TR12-118] TASK AMM12-31-00-660-806 - Inspection and Removal of De-Hydrated Anti-Icing Fluid inside the Flight Control Surfaces" file="TR12-118.pdf" refloc="AMM12-31-00-660-806">
* <folder type="history" title="History of AMM12-31-00-660-806">
* <doc title="TASK 12-31-00-660-806 - Inspection and Removal of De-Hydrated Anti-Icing Fluid inside the Flight Control Surfaces" file="AMM12-31-00-660-806.pdf" type="history" refloc="AMM12-31-00-660-806"/>
* </folder>
* the xpath string should be:
* folder[@key="LOETR"]/doc[@trnum="TR12-118"]/folder[@type="history"]/doc[@type="history"]
*
*
* the String : "fk:AMM24_fk:AMM24-FM_dk:CTOC-24"
* it represents the inner doc with attribute file="CTOC-24.pdf"
* the string : "fk:AMM24_fk:AMM24-00-00_fk:AMM24-00-00-02_dk:AMM24-00-00-700-801" represents
* <folder key="AMM24" title="CH 24 - Electrical Power">
* <folder key="AMM24-FM" title="Front Matter">
* <doc key="CTOC-24" title="Table of Contents" file="CTOC-24.pdf"/>
* </folder>
* <folder key="AMM24-00-00" title="24-00-00 - General">
* <folder key="AMM24-00-00-02" title="General - Maintenance Practices">
* <doc key="AMM24-00-00-700-801" title="TASK 24-00-00-700-801 - AC Power, DC Power and Battery Maintenance Practice Recommendations" file="AMM24-00-00-700-801.pdf"/>
*
* it can be even optimized as :
* "fk:AMM24_fk:00-00_fk:02_dk:AMM24-00-00-700-801"
* if the inner key fully include the previous key, omit it, otherwise use full string
* the xpath string should be:
* folder[@key="AMM24"]/folder[@key="AMM24-00-00"]/folder[@key="AMM24-00-00-02"]/doc[@key="AMM24-00-00-700-801"]
*
* if shortXPath is ?? which means the query based on the root of the document
*
*
*/
public String pathMapping(String shortXPath) throws Exception
{
String tagetString = null;
if (shortXPath.equals(""))
{
tagetString = "//toc";
}
else
{
tagetString = "//";
}
int newStart = 0;
String segString = "";
String valueString = "";
//dth???
//need mapping all senarios
//already??
while (shortXPath.indexOf("_", newStart) > -1)
{
int keyValueSepPos = 0;
String keyString = "";//not necessary key, might be type attribute
segString = shortXPath.substring(newStart, shortXPath.indexOf("_", newStart));
newStart = shortXPath.indexOf("_", newStart) + 1;//new start search point
//System.out.println(newStart);
if (segString.indexOf(":") > 0)
{
keyValueSepPos = segString.indexOf(":");
keyString = segString.substring(0, keyValueSepPos);
valueString = segString.substring(keyValueSepPos + 1);
if (pathMap.get(keyString).length() > 0)
{
tagetString = tagetString.concat(pathMap.get(keyString));
}
else
{
throw new Exception("no mapping found");
}
tagetString = tagetString.concat("='").concat(valueString).concat("']/");
}
}
//this is for scenerio either no "_" or sub string after "_"
segString = shortXPath.substring(newStart);
System.out.println(segString);
if (segString.indexOf(":") > 0)
{
int lastKeyValueSepPos = segString.indexOf(":");
String lastKeyString = segString.substring(0, lastKeyValueSepPos);
String lastValueString = segString.substring(lastKeyValueSepPos + 1);
if (pathMap.get(lastKeyString).length() > 0)
{
tagetString = tagetString.concat(pathMap.get(lastKeyString));
}
else
{
throw new Exception("no mapping found");
}
tagetString = tagetString.concat("='").concat(lastValueString).concat("']");
}
return tagetString;
}
public static void main(String[] args) throws Exception
{
XMLToJson x2j = new XMLToJson();
String test = "fk:AMM24_fk:AMM24-FM";
test = "";
System.out.println(x2j.getJson(new URL("http://localhost:8080/WebNavSpring/q400/amm/toc.xml"), test));
//System.out.println(x2j.pathMapping(test));
}
}
easy clean code to convert XML to JSON .
var move=0;
var kier=0;
var pic=0;
var rol=0;
var rol2=171;
var rol3=343;
var rol4=514;
var rol2_cel=171;
var rol3_cel=343;
var rol4_cel=514;
function onpic(p) {
pic=p;
}
function offpic(p) {
if( pic==p ) pic=0;
}
function next() { if(move<40) move = 40; kier=0; }
function prev() { if(move<40) move = 60; kier=1; }
function set() {
document.getElementById('ba1').style.left=0;
document.getElementById('ba2').style.left=rol2;
document.getElementById('ba3').style.left=rol3;
document.getElementById('ba4').style.left=rol4;
}
function SetOpacity(object,opacityPct)
{
// IE.
object.style.filter = 'alpha(opacity=' + opacityPct + ')';
// Old mozilla and firefox
object.style.MozOpacity = opacityPct/100;
// Everything else.
object.style.opacity = opacityPct/100;
}
var randtim=new Array(110,103,130,125,108,118,112,122,101,100);
var showtimer=0;
var showpic=1;
function Animuj() {
if( pic==0 ) {
rol2_cel=171;
rol3_cel=343;
rol4_cel=514;
} else if( pic==1 ) {
rol2_cel=342;
rol3_cel=457;
rol4_cel=571;
} else if( pic==2 ) {
rol2_cel=115;
rol3_cel=457;
rol4_cel=571;
} else if( pic==3 ) {
rol2_cel=114;
rol3_cel=229;
rol4_cel=571;
} else if( pic==4 ) {
rol2_cel=114;
rol3_cel=228;
rol4_cel=344;
}
var a = (rol2-rol2_cel)/10; if(( a< -0.1 )&&( a> -1 )) a = -1; if(( a>0.1 )&&( a<1 )) a = 1;
if( rol2!=rol2_cel ) rol2-= a;
var a = (rol3-rol3_cel)/10; if(( a< -0.1 )&&( a> -1 )) a = -1; if(( a>0.1 )&&( a<1 )) a = 1;
if( rol3!=rol3_cel ) rol3-= a;
var a = (rol4-rol4_cel)/10; if(( a< -0.1 )&&( a> -1 )) a = -1; if(( a>0.1 )&&( a<1 )) a = 1;
if( rol4!=rol4_cel ) rol4-= a;
set();
document.getElementById('ba2').style.left=rol2;
showtimer+=1;
if(showtimer>100) {
for( st=0; st<9; ++st ) {
if(showtimer==randtim[st]) { SetOpacity(document.getElementById("ps"+st), 0); document.getElementById("ps"+st).style.backgroundImage="url('cs/log"+showpic+".jpg')"; }
if(showtimer==(randtim[st]+1)) SetOpacity(document.getElementById("ps"+st),20);
if(showtimer==(randtim[st]+2)) SetOpacity(document.getElementById("ps"+st),40);
if(showtimer==(randtim[st]+3)) SetOpacity(document.getElementById("ps"+st),60);
if(showtimer==(randtim[st]+4)) SetOpacity(document.getElementById("ps"+st),80);
if(showtimer==(randtim[st]+5)) { document.getElementById("pn"+st).style.backgroundImage="url('cs/log"+showpic+".jpg')"; SetOpacity(document.getElementById("ps"+st),0); }
}
if(showtimer>150) {
showtimer=0;
for( st=0; st<9; ++st ) randtim[st]=Math.floor(Math.random()*26)+100;
showpic+=1; if(showpic>2) showpic=0;
}
}
}
window.setInterval("Animuj()", 50);
This is how public money is spent in poland
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, "%");
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
var token = new CancellationTokenSource().Token;
Task.Factory.StartNew (() => {
while (!token.IsCancellationRequested) {
try {
if (/*Condition*/)
this.Invoke(new Action(() => label.Text = " =)"));
else
this.Invoke(new Action(() => label.Text = " =("));
Thread.Sleep(10);
}
catch (Exception) {
throw;
}
finally {
throw new Exception();
}
}
}) ;
}
}
My collegue's way of using multithreading features (and exceptions handling) :)
double func_atof(char *p){
double integer = 0.0, div = 1.0 , fract = 0.0 , sign = 1.0;
if( *p == 45 ){sign = -1.0, *p++ ; }
while ( isdigit(*p) ) {
integer = ( *p++ ) + (10.0 * integer) - 48.0 ;
}
if(*p == 46 ){
(*p++ ) ;
while ( isdigit(*p) ) {
fract = ( *p++ ) + (10.0 * fract) - 48.0 ;
div *= 10;
}
}
return (integer + fract / div ) * sign ;
}
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
typedef NS_ENUM(NSUInteger, MyEnum1) {
PackagesNo1 = 1,
PackagesNo2 = 2,
PackagesNo4 = 4,
PackagesNo8 = 8
};
typedef NS_ENUM(NSUInteger, MyEnum2) {
LEVEL0 = 0,
LEVEL1 = 1,
LEVEL2 = 2,
LEVEL3 = 3
};
- (int)packagesNeededForLevel:(int)level {
switch (level) {
case LEVEL0:
return PackagesNo8;
case LEVEL1:
return PackagesNo4;
case LEVEL2:
return PackagesNo2;
case LEVEL3:
return PackagesNo1;
}
}
well done mr junior
if (isset($data['phone_id']) && !empty($data['phone_id'])) {
$userPhone = $this->getDoctrine()->getRepository('STODBBundle:Phones')->find($data['phone_id']);
if ($userPhone->getPhoneNumber() != $data['phone'] || $userPhone->getMobileProviderCode()->getId() != $data['phone_code']) {
if ($data['smsCode'] ?? false) {
if ($sessionSmsCode !== $data['smsCode']) {
$aData['smsCodeShow'] = false;
$aData['isWrongCode'] = true;
} else {
$aData['isWrongCode'] = false;
$checkCode = $data['smsCode'];
}
} else {
$aData['smsCodeShow'] = true;
$aData['isWrongCode'] = true;
}
} elseif (!$userPhone->getCodeCheck()) {
if ($data['smsCode'] ?? false) {
if ($sessionSmsCode !== $data['smsCode']) {
$aData['smsCodeShow'] = false;
$aData['isWrongCode'] = true;
} else {
$aData['isWrongCode'] = false;
$checkCode = $data['smsCode'];
}
} else {
$aData['smsCodeShow'] = true;
}
} else {
$aData['isWrongCode'] = false;
}
} else {
if ($data['smsCode'] ?? false) {
if ($sessionSmsCode !== $data['smsCode']) {
$aData['smsCodeShow'] = false;
$aData['isWrongCode'] = true;
} else {
$aData['isWrongCode'] = false;
$checkCode = $data['smsCode'];
}
} else {
$aData['smsCodeShow'] = true;
}
}
shit ... this junior
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