Hi, I loop through 3 cards that you need to be able to set dates in.
The issue is that you can select any of the cards and change the dates.
I need the user to start with the first card and then only after enter the date to be able to move to the next card.
Can anyone please suggest a good way of approaching this?
Thank you
This password validation function in Javascript looks really awful to be honest 😃 Thoughts ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
function checkPassword() { const val = document.querySelector('.session-input > #user_password').value const confirm = document.querySelector('.session-input > #user_password_confirmation').value const email = document.querySelector('.session-input > #user_email').value.split('@')[0] if (val && email) { if (val.length < 16) { document.querySelector('.pw-length').classList.remove('success') document.querySelector('.pw-length').classList.add('error') } else { document.querySelector('.pw-length').classList.remove('error') document.querySelector('.pw-length').classList.add('success') } if (val.search(/[a-z]/) < 0 || val.search(/[A-Z]/) < 0) { document.querySelector('.lower-upper').classList.remove('success') document.querySelector('.lower-upper').classList.add('error') } else { document.querySelector('.lower-upper').classList.remove('error') document.querySelector('.lower-upper').classList.add('success') } if (val.search(/[0-9]/) < 0 || val.search(/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+/) < 0) { document.querySelector('.num-char').classList.remove('success') document.querySelector('.num-char').classList.add('error') } else { document.querySelector('.num-char').classList.remove('error') document.querySelector('.num-char').classList.add('success') } if (val != confirm) { document.querySelector('.pw-match').classList.remove('success') document.querySelector('.pw-match').classList.add('error') } else { document.querySelector('.pw-match').classList.remove('error') document.querySelector('.pw-match').classList.add('success') } if (checkIdenticalConsecutive()) { document.querySelector('.consecutive').classList.remove('success') document.querySelector('.consecutive').classList.add('error') } else { document.querySelector('.consecutive').classList.remove('error') document.querySelector('.consecutive').classList.add('success') } if (val.search(/hydra/) >= 0 || val.toLowerCase().search(email.toLowerCase()) >= 0) { document.querySelector('.name-email-hydra').classList.remove('success') document.querySelector('.name-email-hydra').classList.add('error') } else { document.querySelector('.name-email-hydra').classList.remove('error') document.querySelector('.name-email-hydra').classList.add('success') } } } |
The senior front enders in the company I recently joined are trying to convince me that it's ok to write code like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
divisionHelperTriangle(length, score) { if (score === 2) { return length / 28 } if (score === 3) { return length / 26 } if (score === 4) { return length / 26.5 } if (score === 5) { return length / 27.5 } if (score === 6) { return length / 26 } if (score >= 7) { return length / 25 } return length / 30 } |
Great approach to remove all numbers from a string in PHP via regular expression. PRO level regular expression in PHP 😀 Instead of simple [0-9] or \d look:
1 2 3 4 5 6 7 8 9 10 |
$words = preg_replace('/0/', '', $words ); // remove numbers $words = preg_replace('/1/', '', $words ); // remove numbers $words = preg_replace('/2/', '', $words ); // remove numbers $words = preg_replace('/3/', '', $words ); // remove numbers $words = preg_replace('/4/', '', $words ); // remove numbers $words = preg_replace('/5/', '', $words ); // remove numbers $words = preg_replace('/6/', '', $words ); // remove numbers $words = preg_replace('/7/', '', $words ); // remove numbers $words = preg_replace('/8/', '', $words ); // remove numbers $words = preg_replace('/9/', '', $words ); // remove numbers |
Check if string is palindrome on the Python language
1 2 3 4 5 6 7 8 |
def ispalindrome(string): decide=1 i=0 while i<=int(len(string)/2) and decide==1: if string[i]!=string[-(i+1)]: decide=0 i+=1 return decide |
How to reverse string in Python 😃
1 2 3 4 |
def reverse(s, rs=''): for i in range(1, len(s)): rs = rs + s[len(s)-i] return rs+s[0] |
Nice code in Model of Django Python based framework
1 2 3 4 5 6 7 8 9 10 11 |
# In Django model def processed_description(self): text = self.description. \ replace('<table', '<div class="table">' '<div class="bgtop"></div>' '<div class="overflow"><table'). \ replace('</table>', '</table></div>' '<div class="bgbottom"></div>' '</div>'). \ replace('<th', '<th width="50%" align="left"') return text |
How you do not need programming in Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
if cells[x-1,y-1] == 1: pos+=1 else: Â if cells[x-1,y-1] == -1: neg+=1 if cells[x-1,y] == 1: pos+=1 else: Â if cells[x-1,y] == -1: neg+=1 if cells[x-1,y+1] == 1: pos+=1 else: Â if cells[x-1,y+1] == -1: neg+=1 if cells[x,y-1] == 1: pos+=1 else: Â if cells[x,y-1] == -1: neg+=1 if cells[x,y] == 1: pos+=1 else: Â if cells[x,y] == -1: neg+=1 if cells[x,y+1] == 1: pos+=1 else: Â if cells[x,y+1] == -1: neg+=1 if cells[x+1,y-1] == 1: pos+=1 else: Â if cells[x+1,y-1] == -1: neg+=1 if cells[x+1,y] == 1: pos+=1 else: Â if cells[x+1,y] == -1: neg+=1 if cells[x+1,y+1] == 1: pos+=1 else: Â if cells[x+1,y+1] == -1: neg+=1 |
Summer intern Python code this summer 🤗
1 2 3 4 5 6 7 8 |
try: # do some stuff except: e0 = sys.exc_info()[0] e1 = sys.exc_info()[1] e2 = sys.exc_info()[2] print '*** failed due to: %s %s %s' % (e0, e1, e2) sys.exit(3) |
Goroutines and loop together in Golang 🥰
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
for i := 0; i < fanout; i++ { go func() { for { c.Dec(19) time.Sleep(300e6) } }() go func() { for { c.Inc(47) time.Sleep(400e6) } }() } |
How to write detailed TODO comments in Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# TODO: fix this hell def pretty_print(w, p):   w = truncate(w)   p = truncate(p)   my_matrix = zip(p, w)   print "\n".join(["\t\t".join(["\t".join(map(str, r)) for r in t]) for t in my_matrix])     # TODO: and this def truncate(m):   for i in range(len(m)):     for j in range(len(m[0])):       if(len(str(m[i][j])) > 5):         m[i][j] = "%.3f" % m[i][j]   return m |
Some interesting source code from Android 1.5 🤨
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
if (f.mColor != null) { Â int c = -1; Â if (f.mColor.equalsIgnoreCase("aqua")) { Â Â Â c = 0x00FFFF; Â } else if (f.mColor.equalsIgnoreCase("black")) { Â Â Â c = 0x000000; Â } else if (f.mColor.equalsIgnoreCase("blue")) { Â Â Â c = 0x0000FF; Â } else if (f.mColor.equalsIgnoreCase("fuchsia")) { Â Â Â c = 0xFF00FF; Â } else if (f.mColor.equalsIgnoreCase("green")) { Â Â Â c = 0x008000; Â } else if (f.mColor.equalsIgnoreCase("grey")) { Â Â Â c = 0x808080; Â } else if (f.mColor.equalsIgnoreCase("lime")) { Â Â Â c = 0x00FF00; Â } else if (f.mColor.equalsIgnoreCase("maroon")) { Â Â Â c = 0x800000; Â } else if (f.mColor.equalsIgnoreCase("navy")) { Â Â Â c = 0x000080; Â } else if (f.mColor.equalsIgnoreCase("olive")) { Â Â Â c = 0x808000; Â } else if (f.mColor.equalsIgnoreCase("purple")) { Â Â Â c = 0x800080; Â } else if (f.mColor.equalsIgnoreCase("red")) { Â Â Â c = 0xFF0000; Â } else if (f.mColor.equalsIgnoreCase("silver")) { Â Â Â c = 0xC0C0C0; Â } else if (f.mColor.equalsIgnoreCase("teal")) { Â Â Â c = 0x008080; Â } else if (f.mColor.equalsIgnoreCase("white")) { Â Â Â c = 0xFFFFFF; Â } else if (f.mColor.equalsIgnoreCase("yellow")) { Â Â Â c = 0xFFFF00; Â } else { Â Â Â try { Â Â Â Â Â c = XmlUtils.convertValueToInt(f.mColor, -1); Â Â Â } catch (NumberFormatException nfe) { Â Â Â Â Â // Can't understand the color, so just drop it. Â Â Â } Â } |
Using Javascript setTimeout directly from PHP 😃
1 2 3 4 |
$file=$GLOBALS["LOGFILE"]; if(!is_file($file)){echo "<script>setTimeout(\"Procedure2$t()\",1000);</script>";return;} $data=@file_get_contents($file); if(strlen($data)<10){echo "<script>setTimeout(\"Procedure2$t()\",1000);</script>";return;} |
Thread join implementation in Java
1 2 3 4 5 6 7 |
try { while (sender.isAlive()) { this.sleep(100);//static field usage(!) } } catch (java.lang.InterruptedException e) { Log.log(Log.ERROR, this, e); } |
Render Javascript directly from PHP code. 😜
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
$html=" Â var TIMER$t=0; Â function StartLoadjs$t(){ Â Â YahooWin3('998','$page?popup=yes&t=$t$OnlyRoutes','$title'); Â Â } Â Â function GetLogs$t(){ Â Loadjs('$page?logs=yes&t=$t&setTimeout={$_GET["setTimeout"]}'); Â if(document.getElementById('IMAGE_STATUS_INFO-$t')){ Â Loadjs('admin.tabs.php?refresh-status-js=yes&nocache=yes'); Â } Â } Â function Procedure2$t(){ Â LoadAjax('procedure2-$t','$page?procedure2=yes&t=$t$OnlyRoutes'); Â } Â function Procedure3Error$t(){ Â document.getElementById('procedure3-text$t').value=document.getElementById('procedure3-text$t').value+'\\n'+'Please wait...'; Â setTimeout(\"Procedure3$t()\",1000); Â } Â function Procedure3$t(){ Â document.getElementById('title-$t').innerHTML='$please_wait_building_network'; Â LoadAjax('procedure3-$t','$page?procedure3=yes&t=$t$OnlyRoutes','Procedure3Error$t()'); Â } Â function finish$t(){ Â if(document.getElementById('table-$t')){ Â $('#table-$t').flexReload(); Â } Â Â if(document.getElementById('tabs_listnics2')){ Â RefreshTab('tabs_listnics2'); Â } Â } Â function ApplyNetworkFinalShow1$t(){ Â LoadAjax('ApplyNetWorkFinal-$t','$page?ApplyNetWorkFinal-tests=yes&t=$t$OnlyRoutes'); Â ApplyNetworkFinalShow$t(); Â } Â function ApplyNetworkFinalShow$t(){ Â if(TIMER$t==0){ Â document.getElementById('title-$t').innerHTML='$please_wait_restarting_network'; Â setTimeout(\"ApplyNetworkFinalShow1$t()\",5000); Â } Â } Â Â StartLoadjs$t();"; echo $html; |