Skip to content

Instantly share code, notes, and snippets.

View fabioyamate's full-sized avatar

Fabio Yamate fabioyamate

View GitHub Profile
@fabioyamate
fabioyamate / iframe.html
Last active December 18, 2015 19:19
postMessage
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>postMessage</title>
</head>
<body>
<div id="container">
iFrame
<button>post message</button>
@fabioyamate
fabioyamate / resque-retry.rb
Last active December 18, 2015 18:09
resque failures
describe "job failures" do
it 'retries with limited attempts' do
require 'resque/failure/redis'
Resque.unstub(:enqueue)
Resque::Failure::MultipleWithRetrySuppression.classes = [Resque::Failure::Redis]
Resque::Failure.backend = Resque::Failure::MultipleWithRetrySuppression
JobWithError = Class.new do
@queue = "test"
.inline-block {
background: red;
margin-right: -4px;
}
.with-sidenote:after {
white-space: pre;
}
@fabioyamate
fabioyamate / dabblet.css
Created April 27, 2013 02:24
Circular Tooltip (SO)
/**
* Circular Tooltip (SO)
* http://stackoverflow.com/q/13132864/1397351
*/
* { margin: 0; padding: 0; }
body {
overflow: hidden;
background: url(http://theearlcarlson.com/experiments/amTooltip/img/bg.jpg);
}
/* generic styles for button & circular menu */
@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>