Skip to content

Instantly share code, notes, and snippets.

View malko's full-sized avatar

Jonathan Gotti malko

View GitHub Profile
@malko
malko / printReplace
Created February 21, 2012 20:33
string placeholder replacement function
printReplace=function(str,vars){
if( typeof vars !== 'object' ){
return str;
}
return str.replace(/(%+)([a-z0-9_-]+)/g,function(m,p,k){
if( p.length === 1 && typeof vars[k] !== 'undefined'){
return vars[k] || '';
}
return m;
});
@malko
malko / cookies.js
Created May 4, 2012 14:15
javascript cookies
cookies={
get:function(name){
var re=new RegExp(name+'=([^;]*);?','gi'), result=re.exec(document.cookie)||[];
return (result.length>1? unescape(result[1]): false);
},
set:function(name, value, expirationTime, path, domain, secure){
var time=new Date();
if(expirationTime){
time.setTime(time.getTime()+(expirationTime*1000));
}
@malko
malko / D.js
Last active October 12, 2015 02:47
attempt of a simple defer/promise library for mobile development
/*jshint forin:true, noarg:true, noempty:true, eqeqeq:true, bitwise:true, strict:true, undef:true, unused:true, curly:true, indent:2, maxerr:50, laxcomma:true, expr:true, white:false, expr:true, latedef:true*/
/*global exports*/
/**
* attempt of a simple defer/promise library for mobile development
* @author Jonathan Gotti for agence-modedemploi.com
* @since 2012-10
* @changelog
* - 2013-01-25 - add rethrow method
* - nextTick optimisation -> add support for process.nextTick + MessageChannel where available
* - 2012-12-28 - add apply method to promise
@malko
malko / basic-compat.js
Last active October 12, 2015 02:47
minimalist jquery/zepto compatibility layer targeting mobile platforms library development
/**
* minimal jquery/zepto compatibility layer
* be aware that won't mimic jquery/zepto at all but offer a similar api for basic stuffs as querySelectorAll and addEventListener ...
* @author jgotti at modedemploi dot fr for agence-modedemploi.com
* @licence Dual licence LGPL / MIT
* @changelog
* - 2013-01-18 - add isArray/isFunction/isNumeric/isObject/isEmptyObject/isPlainObject/filter/not methods
* - is/filter/not may now use selector, domElement, function or collection to match against
* - first attempt for adding selectors and namespaces supports to on and off methods
* - 2012-12-11 - add hasClass/addClass/removeClass/toggleClass/hide/show/toggle/is/closest methods
@malko
malko / .zshrc
Created November 19, 2012 14:34
zshrc
PROMPT="$(print '[%{\e[3%(!.1.2)m%}%n@%{\e[0;m%}%m:%{\e[34;m%}%3~%{\e[0m%}]%(!.#.$)') " # default prompt
# Source global definitions
if [ -f /etc/zshrc ]; then
. /etc/zsh/zshrc
fi
# enable color support of ls and also add handy aliases
if [ "$TERM" != "dumb" ]; then
eval "`dircolors -b`"
alias ls='ls --color=auto'
@malko
malko / .vimrc
Created November 19, 2012 14:34
vimrc
" I like highlighted search results
set hlsearch
" Use incremental searching
set incsearch
" Auto indent after a {
set autoindent
set smartindent
" Do not wrap lines automatically
@malko
malko / basic-compat.js
Created November 26, 2012 18:34
touch events support
/**
* minimal jquery/zepto compatibility layer
* be aware that won't mimic jquery/zepto at all but offer a similar api for basic stuffs as querySelectorAll and addEventListener ...
* @author jgotti at modedemploi dot fr for agence-modedemploi.com
* @licence Dual licence LGPL / MIT
* @changelog
* - 2012-11-28 - more jquery like syntax and some events related stuffs
*/
(function($){
"use strict";
@malko
malko / stepl-test.html
Created December 10, 2012 15:57
minimalistic template system
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jsonFilter test suite</title>
<link type="text/css" rel="stylesheet" href="qunit-1.10.0.css" media="all" />
</head>
<body>
<div id="qunit"></div>
@malko
malko / lcdBrightness.sh
Created February 9, 2013 00:49
Shell script for screen brightness setting of ASUS UX32 series under ubuntu 12.10 You can pass a step value as parameter, and should pass negative values to decrease brightness.
#!/bin/sh
# get user step on command line or default to 1
USERSTEP=${1:-1}
# get max and current values of brightness
MAX=`/usr/lib/gnome-settings-daemon/gsd-backlight-helper --get-max-brightness`
CUR=`/usr/lib/gnome-settings-daemon/gsd-backlight-helper --get-brightness`
# define step and min to apply regarding the max value to have approximatively ten levels of settings
STEP=$(($MAX/10))
MIN=$((STEP/2))
# calc new user wanted value
@malko
malko / pager.sh
Last active December 14, 2015 23:49
simple shell program to launch pager (most for now) only if input datas won't fit into screen
#!/bin/bash
pgr="most"
tmpFile="/tmp/pager_$(uuidgen)"
cat - /dev/stdin > $tmpFile;
nblines=$(wc -l $tmpFile |awk '{print($1)}');
if [ "$nblines" -gt "$(tput lines)" ]; then
$pgr $tmpFile
else
cat $tmpFile && echo ""