Skip to content

Instantly share code, notes, and snippets.

Mario Marinero mmarinero

Block or report user

Report or block mmarinero

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mmarinero
mmarinero / github-backup.hs
Last active Nov 1, 2018
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...)
View github-backup.hs
#!/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 Mar 2, 2016
The lastAction object keeps a list of promises that perform stateless actions that need to be executed in order on the server.
View jquery.lastAction.js
(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 Feb 4, 2016
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.
View object_traverse.js
/**
* 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.promiseCache.js
Last active Aug 29, 2015
promiseCache jquery plugin: lacking real world testing but plenty of tests ;).
View jquery.promiseCache.js
(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 / jquery.orderedPromises.js
Last active Aug 29, 2015
Creates an ordered stream of completed promises discarding the previous uncompleted ones.
View jquery.orderedPromises.js
(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.enter.js
Created Oct 8, 2014
Jquery plugin to simulate an event that is binded to the enter key
View jquery.enter.js
/**
* 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 / LICENSE.md
Last active Aug 29, 2015
License for the other gists (MIT)
View LICENSE.md

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.sequence.js
Last active Aug 29, 2015
Promises sequence jquery plugin, with tests and example.
View jquery.sequence.js
(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 Aug 29, 2015
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
View spotify.ahk
;
; 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 Aug 29, 2015
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).
View jQuery.match.js
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 +
You can’t perform that action at this time.