Skip to content

Instantly share code, notes, and snippets.

View makevoid's full-sized avatar

Francesco 'makevoid' Canessa makevoid

View GitHub Profile
@makevoid
makevoid / sinatrize.rb
Last active October 3, 2015 03:57
Sinatrize, generates a base sinatra app
# Sinatrize
# usage:
#
# mkdir -p yourapp
# cd yourapp
# wget https://gist.githubusercontent.com/makevoid/2385559/raw/1fc0355a04ed2153d74b06386048d1e1541a0706/sinatrize.rb # if you are not sure get the latest gist by clicking on [Raw]
# ruby sinatrize.rb
# rm -f sinatrize.rb
# bundle
@makevoid
makevoid / index.html
Created April 26, 2012 12:52
usermedia and webrtc chrome test
<html>
<head>
<script type="text/javascript">
function onFailSoHard() {
console.log("fail")
}
function sendSignalingChannel(message) {
var xhr = new XMLHttpRequest();
xhr.open('POST', path, true);
@makevoid
makevoid / app_delegate.rb
Last active October 4, 2015 06:48
Hello Button in RubyMotion (a bit more than hello world)
# Hello ButtonView (world)
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
@window.rootViewController = ButtonViewController.alloc.init
@window.makeKeyAndVisible
return true
end
end
@makevoid
makevoid / Readme.md
Created June 16, 2012 12:39
Hello meteor with coffeescript

Prereqs:

  • node and npm
  • coffee-script npm package

Install meteor:

curl install.meteor.com | /bin/sh

Clone/copy these files into a directory

@makevoid
makevoid / regex_bench.rb
Created July 10, 2012 13:44
100 thousand matches in 0.3 sec on my machine
# encoding: utf-8
text = <<-LOL
<!DOCTYPE html>
<html class='no-js' lang='en'>
<head>
<meta charset='utf-8'>
<title>5apps</title>
<meta content='Deployment and distribution tools for HTML5 app developers' name='description'>
<meta content='width=device-width, minimum-scale=1.0, maximum-scale=1.0' name='viewport'>
@makevoid
makevoid / livescore_scraper_simple.rb
Created August 29, 2012 05:05
Simple scraper example ruby
# simple scrape example with mechanize
#
# setup: gem install mechanize
require 'mechanize'
agent = Mechanize.new
agent.user_agent = "Mac Firefox"
host = "http://livescore.com/soccer/italy"
@makevoid
makevoid / thorrents_manifest.json
Created August 29, 2012 16:45
Thorrents (hosted) manifest file
{
"name": "Thorrents (hosted)",
"description": "Thor agrees!",
"version": "1.2",
"manifest_version": 2,
"app": {
"urls": [
"http://thorrents.com/"
],
"launch": {
@makevoid
makevoid / uri.js
Created September 6, 2012 10:53 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@makevoid
makevoid / map_reduce.rb
Created October 15, 2012 20:29
map reduce mongoid
map = %Q{
function() {
emit(this.name, { deployments: this.deployments })
}
}
reduce = %Q{
function(key, values) {
var result = {}
values.forEach(function(value) {
@makevoid
makevoid / hsv_rgb_conversion.rb
Created October 19, 2012 13:43
Convert HSV colors to RGB and back (with specs)
# http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically
def hsv_to_rgb(h, s, v)
h, s, v = h.to_f/360, s.to_f/100, v.to_f/100
h_i = (h*6).to_i
f = h*6 - h_i
p = v * (1 - s)
q = v * (1 - f*s)
t = v * (1 - (1 - f) * s)
r, g, b = v, t, p if h_i==0
r, g, b = q, v, p if h_i==1