Skip to content

Instantly share code, notes, and snippets.

View mmarinero's full-sized avatar
🧄

Mario Marinero mmarinero

🧄
View GitHub Profile
@mmarinero
mmarinero / github-backup.hs
Last active November 1, 2018 11:57
Script to backup github repos and gists. My first Haskell script, it's very ugly but works in simple cases (no api pagination support, bad messages...)
#!/usr/bin/env runhaskell
{-# LANGUAGE OverloadedStrings#-}
-- Packages required:
-- aeson 1.4.1.0
-- http-conduit 2.3.2
-- turtle 1.5.12
import qualified Data.ByteString.Lazy as B
import Data.Text
@mmarinero
mmarinero / jquery.lastAction.js
Last active March 2, 2016 21:03
The lastAction object keeps a list of promises that perform stateless actions that need to be executed in order on the server.
(function($) {
"use strict";
/**
* The LastAction object accepts actions (functions that return promises) only executing the last
* action available and dropping the rest. The object also waits for a executed action to complete before
* executing the next one.
* Note: This is a only client side solution to ordering actions, more network efficient solutions
* can be achieved with server collaboration, sequence numbers, acks...
*
* @param {Function} onComplete Executes when an action completes successfully and no action is
@mmarinero
mmarinero / object_traverse.js
Last active February 4, 2016 13:06
Two functions to traverse a chain of objects in Javascript. One to ask for a value at the end and one to place a value and create the intermediate objects if necessary. Both accept a variable length parameter's list or an array.
/**
* Tries to follow a chain of objects starting at base and return the value at
* the end. It uses a string array "mixedChain" to represent the chain and also
* accepts a variable number of string parameters representing the same chain so
* ask(object, ["child1", "child2"]) is equivalent to
* ask(object, "child1", "child2")
* If the chain keys are not strings convert them or use the array syntax
*
* @param {Object} base Root object of the chain to be inspected.
* @param {array[String] | ...String} mixedChain List of strings representing
@mmarinero
mmarinero / jquery.orderedPromises.js
Last active August 29, 2015 14:07
Creates an ordered stream of completed promises discarding the previous uncompleted ones.
(function ($) {
"use strict";
/**
* The orderedPromises object keeps an ordered list of promises for a single
* resource. It provides a next callback that is whenever a more updated
* result is available. This guarantees the order of the results preventing
* old results getting mixed with newer ones.
* The ordering is only kept on the client side so this is ideal for stateless
* requests.
* @param {array} promises An initial list of promises to track, be careful
@mmarinero
mmarinero / jquery.promiseCache.js
Last active August 29, 2015 14:07
promiseCache jquery plugin: lacking real world testing but plenty of tests ;).
(function ($) {
"use strict";
/**
* Partial insertion sort function implemented to create a sorted array
* of promises to evict on one pass
* @param {array[Promise]} promises set of promises to scan
* @param {int} nEvicted number of promises to return
* @param {string} prop key name of the counter on the promise
* @param {Boolean} desc To invert the sort order
@mmarinero
mmarinero / LICENSE.md
Last active August 29, 2015 14:07
License for the other gists (MIT)

The MIT License (MIT)

Copyright (c) 2015 Mario Marinero

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH T

@mmarinero
mmarinero / jquery.enter.js
Created October 8, 2014 23:22
Jquery plugin to simulate an event that is binded to the enter key
/**
* Jquery enter event plugin.
* It will intercept keypress events but only call the handlers
* if the pressed key is Enter
* Events can be binded with the 'enter' event type or the enter function
* The function accepts an option data parameter tha will be passes to the handler function
* and an event handler. If called without parameters it will trigger the event.
*/
jQuery.event.special.enter = {
bindType: "keypress",
@mmarinero
mmarinero / jquery.sequence.js
Last active August 29, 2015 14:07
Promises sequence jquery plugin, with tests and example.
(function ($) {
"use strict";
/**
* Abstracts a sequence of a asynchronous actions, the order of execution of the
* different actions is enforced using deferred objects.
* The successful completion of an action will trigger the start of the next one.
* If an action fails the following actions will fail too until an action with
* fallback is found in the queue (the fallback action will be called then).
*
* Actions consist of a function that receives a Deferred object as its first
@mmarinero
mmarinero / spotify.ahk
Last active August 29, 2015 14:04
Global shortcuts to manage spotify, mute the audio and use the arrows with alt + vim commands. Not working with since Spotify 1.0.2.6
;
; AutoHotkey Version: 1.x
; Language: English
; Platform: Win9x/NT
; Author: M. Marinero <mariomarinero@gmail.com>
;
; Script Function:
; Shortcuts to manage spotify, mute the audio and use the arrows with alt + vim commands
; Not working since Spotify 1.0.2.6
;
@mmarinero
mmarinero / jQuery.match.js
Last active August 29, 2015 14:03
Jquery match plugin, works like .find() but throws errors on empty selectors or when the number of elements found doesn't match the second parameter (optional).
jQuery.fn.extend({
match: function(selector, matched) {
var result = this.find(selector);
if (matched === undefined && !result.length) {
throw new Error("Not matched elements for selector" + selector);
}
if (matched !== undefined && result.length !== matched) {
throw new Error("Found elements don't match expected ones: " +
"expected: " + matched +
", found: " + result.length +