Skip to content

Instantly share code, notes, and snippets.

View fabioyamate's full-sized avatar

Fabio Yamate fabioyamate

View GitHub Profile
@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 / 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 / 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
<!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>
(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))
@fabioyamate
fabioyamate / nth-last-child.html
Created October 16, 2014 19:50
nth-last-child
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
li:nth-last-child(3) { background-color: red; }
</style>
</head>
<body>
<div id="container">
@fabioyamate
fabioyamate / affix-sandbox.html
Created December 17, 2014 20:49
Affix test
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Snippet</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<style>
#text {height: 100%; background-color: pink}
#header { background-color: red; }
#header.affix {
@fabioyamate
fabioyamate / event_target.js
Created December 19, 2014 13:42
EventTarget mixin module
// draft
(function(exports) {
var ArrayProto = Array.prototype;
var nativeSlice = ArrayProto.slice,
nativeFilter = ArrayProto.filter;
/* Internal: filters the collection. (extracted from underscore.js)
*
@fabioyamate
fabioyamate / .screenrc
Created May 22, 2015 11:44
.screenrc file
# http://www.gnu.org/software/screen/manual/html_node/Command-Summary.html#Command-Summary
# Turn off start message
startup_message off
termcapinfo rxvt-unicode 'hs:ts=\E]2;:fs=\007:ds=\E]2;screen\007'
term screen
# Message to display in the status line when activity is detected in a
# monitored window.
@fabioyamate
fabioyamate / core.clj
Created August 31, 2015 03:20
Stub HTTP server
(ns stubhttp.core
(:require [ring.adapter.jetty :as r]
[ring.middleware.json :as json]
[ring.util.response :as response]))
(def state (atom {}))
(defn register! [{uri "uri" {:strs [status headers body]} "response"}]
(swap! state assoc uri {:status status :headers headers :body body}))