Skip to content

Instantly share code, notes, and snippets.

View web20opensource's full-sized avatar
🎯
Focusing

Mario Ruiz web20opensource

🎯
Focusing
View GitHub Profile
@necolas
necolas / snippet.js
Created June 14, 2011 20:36
Optimised async loading of cross-domain scripts
/*
* Updated to use the function-based method described in http://www.phpied.com/social-button-bffs/
* Better handling of scripts without supplied ids.
*
* N.B. Be sure to include Google Analytics's _gaq and Facebook's fbAsyncInit prior to this function.
*/
(function(doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],
anonymous
anonymous / jsbin.orupad.html
Created July 28, 2013 08:23
<html>
<head>
<title>Test Suite</title>
<script>
function assert( value, desc ) {
var li = document.createElement("li");
li.className = value ? "pass" : "fail";
li.appendChild( document.createTextNode( desc ) );
document.getElementById("results").appendChild( li );
}
function* zs1(n) {
"use strict";
if (n <= 0) throw new Error('positive integer only');
yield [n];
var x = new Array(n);
x[0] = n;
for (var i = 1; i < n; i++) x[i] = 1;
@web20opensource
web20opensource / load event attachEvent addEventListener cross-browser
Created February 18, 2015 16:48
using the cross-browser event handler await until the load event happens and execute a callback
function attachEventApart(object, cB, event, onEvent){
if (object.addEventListener){
object.addEventListener(event, cB, false);
}
else if (window.attachEvent){
object.attachEvent(onEvent, cB);
}
else
object[onEvent] = cB;
}
@web20opensource
web20opensource / happyNumbers
Last active August 29, 2015 14:17
The max safe integer representation in js is a Happy Number :) . Number.MAX_SAFE_INTEGER
var myHN = function (){
var happyClosure = function(number){
//started at
var timeStamp = new Date().getTime();
//save original number
var happyNumber = number;
//iterations done
@web20opensource
web20opensource / anaGram
Created March 24, 2015 16:47
Check if the given words are an anagram
(function(){
var first_words = ["iceman","animal"];
var second_words = ["cinema","lamina"];
check_anagrams(first_words, second_words);
function check_anagrams(first_words, second_words) {
// To print results to the standard output please use console.log()
// Example: console.log("Hello world!");
function anagram(first_word,second_word){
firstArr = first_word.split('');
@web20opensource
web20opensource / palindrome
Last active August 29, 2015 14:17
Check if a given text is a palindrome
var isPalindrome = function(text){
while(text.length!=1){
var firstChar = text.charAt(0);
var lastChar = text.charAt(text.length-1);
if (firstChar===lastChar){
text = text.substr(1,text.length-2);
}
else{
return false;
}
@web20opensource
web20opensource / _map.js
Last active August 29, 2015 14:18
mapping with map js javascript
console.time('mapping in js');
var isAType = {};
isAType._array = "[object Array]";
isAType._function = "[object Function]";
isAType._string = "[object String]";
isAType.isFunction = function(fn) {
return Object.prototype.toString.call(fn) === this._function;
}
#include <dlfcn.h>
void OverrideForRecording() {
NSInteger (*SBSSpringBoardServerPort)() = dlsym(RTLD_NEXT, "SBSSpringBoardServerPort");
NSInteger (*SBSetShowsOverridesForRecording)(NSInteger, NSInteger) = dlsym(RTLD_NEXT, "SBSetShowsOverridesForRecording");
SBSetShowsOverridesForRecording(SBSSpringBoardServerPort(), 1);
}
var fib = [1,2] , i=0;j=1 , index=2 , sum=2;
while ( fib[j]<4*Math.pow(10,6) ){
fib[index] = fib[i]+fib[j];
if (4*Math.pow(10,6)<=fib[index]) {
break;
}
if ( !(fib[index]%2) )
sum+=fib[index];