Skip to content

Instantly share code, notes, and snippets.

View fabioyamate's full-sized avatar

Fabio Yamate fabioyamate

View GitHub Profile
(defn transpose [m]
(apply mapv vector m))
(defn rotate-left [m]
(apply mapv vector (map reverse m)))
(defn- combine [[x y & xs :as row]]
(cond (empty? row) nil
(nil? y) (list x)
(= x y) (cons (* x 2) (combine xs))
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Snippet</title>
</head>
<body>
<a href="event">event</a>
<ul id="container">
</ul>
@fabioyamate
fabioyamate / lazy.js
Last active August 29, 2015 14:05
Lazy evaluation implemented in Javascript (well just because it has strict evalution)
function empty_list() {
return null;
}
// concat :: [[a]] -> [a]
function concat(xs) {
return foldr(append, empty_list, xs);
}
// foldr :: (a -> b -> b) -> b -> [a] -> b
@fabioyamate
fabioyamate / promise.js
Created June 9, 2014 20:37
Promise polyfill with jQuery Deferreds
function Promise(fn) {
this.promise = $.Deferred(function(dfd) {
fn(dfd.resolve, dfd.fail);
}).promise();
}
Promise.prototype.then = function(done, fail) {
this.promise.then(done, fail);
};
@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>
@fabioyamate
fabioyamate / struct_fn.c
Created May 12, 2014 22:10
struct in C
struct my_struct lookup(int count, const struct my_struct coll[], char value[]) {
int i;
for (i = 0; i < count; ++i) {
if (strcmp(coll[i].attr, value) == 0) {
return coll[i];
}
}
return NULL;
}
@fabioyamate
fabioyamate / shota.rb
Created April 27, 2014 15:28
Google Code Jam 2014 Round 1A
require 'scanf'
def flip(mask, os)
os.map { |o| mask ^ o }
end
Infinity = 1.0/0
def solve(n, l, flows, required_flows)
outlets = flows.split(" ").map { |f| f.to_i(2) }
@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
//
<!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