Skip to content

Instantly share code, notes, and snippets.

@mjlescano
mjlescano / Readme.md
Last active December 15, 2023 06:52
Bash command to copy permissions from a file to other(s).
@mjlescano
mjlescano / m
Last active August 29, 2015 14:20
`mpg123` wrapper. It enables by default keyboard shortcuts and play directories.
#!/bin/bash
if [[ -d "$*" ]]; then
find "${*%/}" -iname '*.mp3' -print0 -exec $0 {} +
else
mpg123 -C "$@"
fi
@mjlescano
mjlescano / retry
Last active August 29, 2015 14:20 — forked from dansimau/gist:842415
Bash function for running a command, checking the return code, and re-trying it `x` times after `y` sleep seconds.
#!/bin/bash
# Usage:
# retry <commands...>
# retry <retry times> <commands...>
# retry <retry times> <retry wait> <commands...>
if [[ $2 =~ ^-?[0-9]+$ ]]; then
cmd="${@:3}"
retry_times=$1
@mjlescano
mjlescano / waitFor.js
Last active August 29, 2015 14:15
Silly lib that executes a given callback when a variable is defined on window.
/**
* waitFor.js
*
* Silly lib that executes a given callback when a variable is defined on window.
*
* Matías Lescano | @mjlescano
* Licensed under the MIT license
*/
;if( !window.waitFor ) (function(w){
@mjlescano
mjlescano / css-guides.scss
Created December 31, 2014 04:40
Guides for working with css. Mixins to creates guides like the ones from photoshop.
@mixin css-guide {
content: '';
position: absolute;
opacity: 0.3;
background-color: cyan;
}
@mixin css-guide-h {
@include css-guide;
left: 0;
@mjlescano
mjlescano / loadCachedCss.js
Last active August 29, 2015 14:10
Synchronous css loading, but caching it on localStorage. Based on https://gist.github.com/hdragomir/8f00ce2581795fd7b1b7, to be used on http://goodpeople.com
;(function(w, d){
var rAF = w.requestAnimationFrame
|| w.mozRequestAnimationFrame
|| w.webkitRequestAnimationFrame
|| w.msRequestAnimationFrame
|| function(f){ setTimeout(f, 0) }
var s = window.localStorage
var available = null
@mjlescano
mjlescano / svg-fallback.html
Created November 6, 2014 15:18
Fallback for .svg <img>, tries to load the .png version.
<img src="sarasa.svg" onerror="this.onerror=null;this.src=this.src.replace(/.svg$/, '.png')">
@mjlescano
mjlescano / git-minimal-aliases.sh
Last active November 13, 2019 18:59
Git Minimal aliases. e.g "push" to push current branch
alias status="_exec git status"
alias s="git status --short"
alias fetch="_exec git fetch"
alias stash="_exec git stash"
alias commit="_exec git commit"
alias checkout="_exec git checkout"
alias add="_exec git add"
alias diff="_exec git diff"
alias co="checkout"
@mjlescano
mjlescano / share.js
Created October 22, 2014 01:40
Javascript helpers to share urls programatically, on facebook or twitter
var S = module.exports = {}
/**
* If the page has og:meta tags facebook will parse the page and read them.
* So the options are optionals.
*/
S.onFacebook = function(options, callback){
// New implementation
// https://developers.facebook.com/docs/reference/dialogs/feed/
if( callback ) {
@mjlescano
mjlescano / jquery.openSelect.js
Created October 21, 2014 13:48
Plugin to open the dropdown of a select element
/*
* jQuery openSelect
*
* Matías Lescano | @touteo
* Licensed under the MIT license
*/
;(function($){
$.fn.openSelect = function(options){
return this.each(function(){