Skip to content

Instantly share code, notes, and snippets.

View fabioyamate's full-sized avatar

Fabio Yamate fabioyamate

View GitHub Profile
@fabioyamate
fabioyamate / overlay.js
Created November 22, 2013 13:02
A simple lib to create popup/tooltips
(function(window, $) {
var containers = [];
// Public: position a container overlayed close to the target
//
// container - the container id
// callback - a function callback that receives 'container' and 'target'
//
// Examples
//
@fabioyamate
fabioyamate / maybe.html
Created May 21, 2014 21:29
Playground for a monad maybe implementation in Javascript
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Snippet</title>
</head>
<body>
<div id="container"></div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore-contrib/0.1.4/underscore-contrib.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hello world</title>
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.3.0/pure-min.css">
</head>
<body>
<div class="pure-g-r" id="layout">
<div class="pure-u-1">
@fabioyamate
fabioyamate / apache.conf
Last active December 26, 2015 00:38
Apache2 assets config
# a2enmod headers expires
SetEnv no-gzip
<LocationMatch "^/assets/.*\.(css|js)$">
RewriteEngine on
# Make sure the browser supports gzip encoding before we send it,
# and that we have a precompiled .gz version.
RewriteCond %{HTTP:Accept-Encoding} \b(x-)?gzip\b
@fabioyamate
fabioyamate / polling.js
Last active December 25, 2015 20:09
polling using jQuery deferred with timeout, similar to go channels
/* Performs a pooling with a timeout limit and throttle frequency.
fn - a function that returns a promise of an async computation
timeout - time in milliseconds to cancel pooling (default 10s)
throttle - the minimumm time between pollings
Use throttle if the async computation is too fast and you want
that occurrances happens in intervals.
*/
var polling = function(fn, timeout, throttle) {
@fabioyamate
fabioyamate / type_checking.rb
Created October 11, 2013 01:04
type checking
# gem install mar
# this only checks at runtime, so it doesn't verify the type at compilation
require 'mar'
def type_check(type, value)
value.is_a?(type) or raise "#{value} is not type of #{type}"
end
def type_signature(*types)
var quotes = [{ symbol: 'MSFT', price: 27.01 },
{ symbol: 'INTC', price: 21.75 },
{ symbol: 'MSFT', price: 27.96 },
{ symbol: 'MSFT', price: 31.21 },
{ symbol: 'INTC', price: 22.54 },
{ symbol: 'INTC', price: 20.98 },
{ symbol: 'MSFT', price: 30.73 }]
function priceIncrease(w) {
return w[1].price / w[0].price - 1;
#!/bin/bash
# Run the script as root user
#
# copy the script to the /root and chmod +x to the file.
#
# $ ./rbenv-install-system-wide.sh
#
# and wait
#!/usr/bin/env ruby
require 'socket'
test_file = ARGV[0]
socket = UNIXSocket.new('testing.sock')
socket.write(test_file)
socket.close_write
@fabioyamate
fabioyamate / reduce.rb
Created June 26, 2013 04:23
reduce application
# the common thinking when you are transforming some data to a non-nil value is use map
a = { foo: 'bar', bar: 'baz' }
[:foo, :bar, :baz, :foobar].map { |k| a[k] }
# => ['bar', 'baz', nil, nil]
# to drop nil cases
[:foo, :bar, :baz, :foobar].map { |k| a[k] }.compact
# => ['bar', 'baz']