Skip to content

Instantly share code, notes, and snippets.

View sadasant's full-sized avatar
👁️

Daniel Rodríguez sadasant

👁️
View GitHub Profile
@sadasant
sadasant / euler5.js
Created February 5, 2012 23:57
Euler Problem 5 in JavaScript
// Euclidean Algorithm
function gcd(a,b) { while (b) { var t = b; b = a%b; a = t } return a }
function lcm() { return Array.prototype.reduce.call(arguments, function(a,b){ return (a*b)/gcd(a,b) }) }
// http://projecteuler.net/problem=5
// lcm(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,1,18,19,20)
// but we only need... ehm... primes but from last to first?
lcm(20, 19, 18, 17, 16, 15, 14, 13, 12, 11)
@sadasant
sadasant / fly.js
Created February 10, 2012 18:24
fly
// 1kFly.js ~ sadasant.com
// http://jsbin.com/aluyax/3
function fly(f,mx,my,gx,gy,tx,ty,b,X,Y,x,y,i,r,M,a,w,W,w1){
with(document){
var h=["☼❤☼"," ❤"],
P=M.PI*i,A=M.abs,
D=.7+Math.random()*.7,
p=createElement('p'),s,
o=onmousemove;(s=p.style).fontFamily="monospace";s.position="fixed"
body.appendChild(p)
@sadasant
sadasant / Resources
Created May 4, 2012 19:27 — forked from csanz/hackathons101.md
Hackathons 101
How to organize and run your own hackathon by Peter Moran: https://www.youtube.com/watch?v=1nk2zJ2GTkQ
var points;
function initialize() {
$('#mapModal').modal('show');
points = [{% for point in google.points %}
{
center: new google.maps.LatLng({{ point.lat }}, {{ point.lng }}),
metrics: [{% for metric in point.metrics %}
{
'name': '{{ metric.name }}',
'value': '{{ metric.value }}'
@sadasant
sadasant / connecting.js
Created June 2, 2012 19:19
Connecting to mongolabs example
/**
* Dependencies.
*/
var MongoStore = require('connect-mongo')
, mongoose = require('mongoose')
, express = require('express')
, app = module.exports = express.createServer()
/**
* Connecting.
<?PHP
// b
// Copyright (C) 2012 Daniel Rodríguez (sadasant.com)
// License: GNU General Public License 3.0
// Settings
$s = array(
'rw_menu_on' => 6 // Number of updates before rewriting the menu session
, 'articles_per_page' => 6 // Number of articles per page
, 'blog_location' => 'http://sadasant.com/b/'
@sadasant
sadasant / loops.js
Created June 29, 2012 17:30
Fastest JavaScript Loop
var d1, d0=new Date(); for(var i=0; i<99999; i++);d1=new Date();d1-d0;
// 2431
var d1, d0=new Date(); for(var i=0>>0; i<99999>>0; i++);d1=new Date();d1-d0;
// 2361
var i=0>>0, l=9999>>0, d1, d0=new Date(); for(; i<l; i++);d1=new Date();d1-d0;
// 318
var i=0, l=9999, d1, d0=new Date(); for(; i<l; i++);d1=new Date();d1-d0;
@sadasant
sadasant / map.js
Created July 15, 2012 03:08
Map Twitter Favorites
// Go to https://api.twitter.com/1/favorites.json?count=200&screen_name=sadasant
TWEETS = JSON.parse(document.body.firstChild.innerHTML)
mapped_tweets = []
function mapper(e){
if(e.user.screen_name==='sadasant')
mapped_tweets.push({
id: e.id_str
, date: e.created_at
@sadasant
sadasant / reload.js
Created August 6, 2012 15:26
Reload CSS with jQuery
$($('link')[0]||$('style')[0]).remove();$.get('/css/style.css', function(d){$('head').append($('<style/>').html(d))})
var assert = require('assert')
/*
Fizzbuzz
*/
function FizzBuzz (number) {
if (number % 3 == 0 && number % 5 == 0) return 'fizzbuzz'
else if (number % 3 == 0) return 'fizz'
else if (number % 5 == 0) return 'buzz'
else return number