Skip to content

Instantly share code, notes, and snippets.

View malko's full-sized avatar

Jonathan Gotti malko

View GitHub Profile
@malko
malko / npmMonthlyStats.js
Created February 4, 2014 13:33
get monthly npm statistics for given package name
function npmMonthlyStats(pkgName){
var xhr=new XMLHttpRequest()
, rows
, obj={}
;
xhr.open('GET','https://isaacs.iriscouch.com/downloads/_design/app/_view/pkg?group_level=2&start_key=%5B%22' + pkgName + '%22%5D&end_key=%5B%22' + pkgName + '%22,%7B%7D%5D', false);
xhr.send();
rows=JSON.parse(xhr.responseText).rows;
rows.forEach(function(v,k){
var d = v.key[1].slice(0,7);
@malko
malko / gist:c5403a9312e0ffe98fbb
Created August 12, 2014 09:49
shortest cross platform onReady document
/**
* very poor (but short and easy) cross platform implementation to detect dom readiness
*/
function onReady(fn){
document.body ? fn() : setTimeout(function(){ onReady(fn);},50);
};
@malko
malko / parseBindingAttr
Created February 2, 2015 16:59
parseBindingAttr for angular
/** By J.louis */
function parseExprAttr($parse, $scope, $attrs, name) {
var fn = $parse($attrs[name]),
res
;
res = function (locals) {
return fn($scope, locals);
};
res.assign = fn.assign && function (value) {
fn.assign($scope, value);
/**
Tim Down reply at
http://stackoverflow.com/questions/6690752/insert-html-at-caret-in-a-contenteditable-div/6691294#6691294
*/
function pasteHtmlAtCaret(html) {
var sel, range;
if (window.getSelection) {
// IE9 and non-IE
sel = window.getSelection();
if (sel.getRangeAt && sel.rangeCount) {
@malko
malko / date-functions.js
Last active September 21, 2015 16:25 — forked from kmturley/data-functions.js
Re-written date functions to not use eval() original gist https://gist.github.com/xaprb/8492729 modified by @kmturley
/*
* Copyright (C) 2004 Baron Schwartz <baron at sequent dot org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, version 2.1.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
@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 / 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 / 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 / .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