Skip to content

Instantly share code, notes, and snippets.

View midned's full-sized avatar
🏠
Working from home

Álvaro C midned

🏠
Working from home
  • Vitech
  • Montevideo
View GitHub Profile
@midned
midned / gist:3784611
Created September 25, 2012 21:37
Gravatar in Coffeescript
Gravy =
"HTTP_URL": "http://www.gravatar.com/avatar/"
"HTTPS_URL": "https://secure.gravatar.com/avatar/"
valid: (email) ->
/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i.test email
to: (email, size, https) ->
@midned
midned / gist:4310271
Created December 16, 2012 17:54
My way to convert decimal to hexadecimal and vice versa in Ruby
class Fixnum
def to_hex
self.to_s 16
end
end
class String
def to_i_from_hex
self.to_i 16
end
<?php
$resolver = new Illuminate\Database\ConnectionResolver;
$resolver->setDefaultConnection('default');
$factory = new Illuminate\Database\Connectors\ConnectionFactory;
$connection = $factory->make(array(
'host' => 'localhost',
@midned
midned / demo.coffee
Last active December 13, 2015 20:28
Handle the routes in Javascript using HTML5 pushState (uses Zepto.js and https://github.com/balupton/History.js)
# Create the router that will handle routes to 'site.com/app'
router = new Routy.Router 'app'
# also you can:
# router = new Routy.Router 'app', 'a.routy-link'
# to only listen clicks to links with the "routy-link" class
# or:
# router = new Routy.Router 'app', null, '#container'
# to listen clicks for every link inside the element with the "container" id
# this will handle 'app/' and 'app/home'
(coffee -o ../assets/js -cw coffee) & (jade -w -P jade/index.jade --out ../) & (stylus --out ../assets/css -w stylus) &
function $(selector, context)
{
if (!(context instanceof Element)) {
context = document;
}
return context.querySelectorAll(selector);
}
// querySelectorAll() returns a NodeList object so we need to get the first one
@midned
midned / gist:5887752
Last active December 19, 2015 03:08
Event listening with #swag
Node.prototype.on = Node.prototype.addEventListener;
Node.prototype.off = Node.prototype.removeEventListener;
var elem = document.getElementById('some-element');
function yolo(){
console.log('yolo');
}
elem.on('click', yolo);
@midned
midned / gist:6587105
Last active February 18, 2016 14:45
fun attack
setInterval(function(){
document.body.style.background = 'rgba('+Math.floor(Math.random()*255)+', '+Math.floor(Math.random()*255)+', '+Math.floor(Math.random()*255)+', 1)';
},50);
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char* argv[]) {
int opcion;
int numero;