Skip to content

Instantly share code, notes, and snippets.

View fabioyamate's full-sized avatar

Fabio Yamate fabioyamate

View GitHub Profile
@fabioyamate
fabioyamate / transliterate.js
Created April 22, 2013 23:52
transliterate string given a table conversion
// transliterate (Char a) :: [a] -> [a] -> [a] -> [a]
var transliterate = function(from, to) {
var approximations = {};
for (var i = 0, len = from.length; i < len; ++i) {
approximations[from.charAt(i)] = to.charAt(i);
}
return function(input) {
return input.replace(/[^\x00-\x7f]/g, function(char) {
@fabioyamate
fabioyamate / example.js
Last active December 15, 2015 20:09
Mediator pattern for event stream with context bind.
var person = { name: "John" };
window.name = "Paul";
mediator.on("call-people", function() {
console.log(this.name); // print "Paul"
});
mediator.on("call-people", function() {
console.log(this.name); // print "John"
(def check-sum
(fn [sequence]
(apply + (map (fn [position digit]
(* digit (if (odd? position) 1 3)))
(range 1 (inc (count sequence)))
sequence))))
(defn check-sum-upc [coll]
(apply + (map *
(take (count coll) (cycle '(1 3)))
@fabioyamate
fabioyamate / answer.clj
Last active December 15, 2015 11:18
Given a list of list of integers, return the first item in each sublist, in a way that no duplication is occurred
(defn add-first-uniq [target coll]
(cond (not (contains? target (first coll)))
(conj target (first coll))
:else
(add-first-uniq target (rest coll))))
(reduce add-first-uniq
#{}
'((1 2 3) (1 2) (4 5)))
@fabioyamate
fabioyamate / monads.clj
Last active December 15, 2015 06:49
Some notes to use repl with clojure libraries
; might not be the proper way to do it, but it is how I was able to run repl with some libraries
; in this case I created a lein project, add the monad dependency to the project, and then started
; a repl session, and run:
;
; need to include pomegranate
;
; it seems to be the best way to deal with it
;
(use '[cemerick.pomegranate :only (add-dependencies)])
(add-dependencies :coordinates '[[org.clojure/algo.monads "0.1.4"]])
@fabioyamate
fabioyamate / calendar.html
Created March 16, 2013 05:00
YUI Calendar Picker
<style>
.yui3-overlay-hidden {
visibility: hidden;
}
</style>
<input type="text" id="input-date" />
<div id="calendar-overlay">
<div class="yui3-widget-bd" id="calendar"></div>
@fabioyamate
fabioyamate / model.rb
Created February 26, 2013 20:36
MongoDB Moped rename collection
# Since Mongoid switched to its own driver, many of the mongo API
# (available in mongo-ruby-drive) are missing. This is allows you
# to rename a collection thru command message.
#
# Be aware that the API constantly changes in mongoid
#
# Mongoid (3.1.0), Moped (1.4.2)
class MyModel
include Mongoid::Document
@fabioyamate
fabioyamate / Gemfile
Created February 26, 2013 18:35
Export MongoDB system.profile collection to csv format with some friendly visualization
source "https://rubygems.org"
gem "mongo", "~> 1.8.2"
gem "bson_ext", "~> 1.8.2"
gem "actionpack", "~> 3.2.12"
@fabioyamate
fabioyamate / mover
Last active November 7, 2023 02:30
unRAID mover script
#!/bin/bash
# This is the 'mover' script used for moving files from the cache disk to the
# main array. It is typically invoked via cron.
# After checking if it's valid for this script to run, we check each of the top-level
# directories (shares) on the cache disk. If, and only if, the 'Use Cache' setting for the
# share is set to "yes", we use 'find' to process the objects (files and directories) of
# that directory, moving them to the array.
@fabioyamate
fabioyamate / hundred.rb
Created June 20, 2012 02:42
Finding expression that evaluate to 100
require 'pp'
require 'benchmark'
# compute all possible expressions to the given string of digits to a given set of operations.
# the digits are kept in order
#
# ex. 1234
# generates: 1234, 1+234, 1-234, 12+34, 123-4...
#
# but selects only expressions that evaluate to a given value