Seja um vetor declarado por:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getFnName(fn) { | |
| var f = typeof fn == 'function'; | |
| var s = f && ((fn.name && ['', fn.name]) || fn.toString().match(/function ([^\(]+)/)); | |
| return (!f && 'not a function') || (s && s[1] || 'anonymous'); | |
| } | |
| console.log(getFnName(String)); // 'String' | |
| console.log(getFnName(function test(){})); // 'test' | |
| console.log(getFnName(function (){})); // 'anonymous' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import operator | |
| def fact(n, total=1): | |
| if n <= 1: | |
| return total | |
| return fact(n-1, n * total) | |
| def fact(n): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Number.prototype.toBinaryString = function(){ | |
| var bit = 32, s = ""; | |
| while(bit--) | |
| s += ((this >>> bit) & 1); | |
| return s | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // moment.js locale configuration | |
| // locale : brazilian portuguese (pt-br) | |
| // author : Caio Ribeiro Pereira : https://github.com/caio-ribeiro-pereira | |
| (function (factory) { | |
| if (typeof define === 'function' && define.amd) { | |
| define(['moment'], factory); // AMD | |
| } else if (typeof exports === 'object') { | |
| module.exports = factory(require('../moment')); // Node | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/fibFormula.html | |
| function fibonacci_nth(i){ | |
| var v5 = Math.sqrt(5), | |
| Phi = ( v5 + 1 ) / 2, | |
| phi = Phi-1; | |
| return Math.round( Math.pow(Phi, i) / v5 - Math.pow(-phi, i) / v5 ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function teste_unicode_regex($value) { | |
| $min = (preg_match("/\\p{Ll}/u", $value)) ? "Sim" : "Não" ; | |
| $mai = (preg_match("/\\p{Lu}/u", $value)) ? "Sim" : "Não" ; | |
| $num = (preg_match("/\\d/", $value)) ? "Sim" : "Não" ; | |
| echo <<<TEXT | |
| === $value === |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <? | |
| // | |
| // This is the result of about an hour's delving into PHP's hairy-ass serialization internals. | |
| // PHP provides a session_decode function, however, it's only useful for setting the contents of | |
| // $_SESSION. Say, for instance, you want to decode the session strings that PHP stores in its | |
| // session files -- session_decode gets you nowhere. | |
| // | |
| // There are a bunch of nasty little solutions on the manual page[1] that use pretty hairy regular | |
| // expressions to get the job done, but I found a simple way to use PHP's unserialize and recurse | |
| // through the string extracting all of the serialized bits along the way. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // jQuery version | |
| $(document).on('click', '.js-line-number', function(event){ | |
| var elem = $(this).next('.js-file-line'), | |
| bg_color = elem.css('backgroundColor'), | |
| color_active = 'rgb(248, 238, 199)'; | |
| elem.css('backgroundColor', bg_color === color_active ? 'rgba(0, 0, 0, 0)' : color_active); | |
| }); | |
| var elem = $(document.location.hash).trigger('click'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function valid_date(str_data) { | |
| var regex = /^\d{2}\/\d{2}\/\d{4}$/, | |
| d, m, y; | |
| str_data = str_data.trim(); | |
| if (!regex.test(str_data)) { | |
| return false | |
| } |