Skip to content

Instantly share code, notes, and snippets.

Avatar

Fabio Yamate fabioyamate

View GitHub Profile
View 2048.clj
(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))
View pageshow.html
<!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 Aug 29, 2015
Lazy evaluation implemented in Javascript (well just because it has strict evalution)
View lazy.js
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 Jun 9, 2014
Promise polyfill with jQuery Deferreds
View promise.js
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
Playground for a monad maybe implementation in Javascript
View maybe.html
<!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>
View struct_fn.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 Apr 27, 2014
Google Code Jam 2014 Round 1A
View shota.rb
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 Nov 22, 2013
A simple lib to create popup/tooltips
View overlay.js
(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
//
View blog.html
<!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 Dec 26, 2015
Apache2 assets config
View apache.conf
# 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