Skip to content

Instantly share code, notes, and snippets.

View shesek's full-sized avatar

Nadav Ivgi shesek

View GitHub Profile
@shesek
shesek / install.sh
Created September 15, 2014 09:12
Install all nodejs packages contained in sub-directories
find . -type f -name package.json ! -path ./package.json ! -path '*node_modules*' | xargs -I '{}' sh -c 'cd $(dirname {}) && npm install'
@shesek
shesek / README.md
Last active August 29, 2015 14:13
A simple approach for handling the dom-ready event

A simple approach for handling the dom-ready event

This script is a simple, lazy and hacky replacement for dealing with the dom-ready event (DOMContentLoaded and friends). Basically, it relies on DOM parsing and script execution order by simply putting a script tag at the very end of the document and having it call a list of registered callbacks.

Because of the way the DOM rendering process works, we can guarantee that by the time that script gets executed the DOM is fully ready for use.

Usage

@shesek
shesek / keybase.md
Created May 27, 2015 20:55
Keybase proof

Keybase proof

I hereby claim:

  • I am shesek on github.
  • I am nadav (https://keybase.io/nadav) on keybase.
  • I have a public key whose fingerprint is 948A C570 261E 66CA 7291 0A0A 4B33 3941 E3B4 3EDD

To claim this, I am signing this object:

@shesek
shesek / Chainable.php
Created July 21, 2011 07:11
Chainable wrapper for PHP
<?php
class Chainable {
private $obj;
private $result;
public function __construct($obj){
$this->obj = $obj;
}
public function __call($method, $args) {
if (substr($method, 0, 1) == '_') {
array_unshift($args, $this->result);
@shesek
shesek / ResourceWrapper.php
Created July 21, 2011 07:23
Generic PHP object wrapper for resources
<?php
/**
* A wrapper class for PHP resourcse.
*
* Used for wrapping PHP resources in an object, and working with them in an
* Object-Oriented manner.
*
* Some methods are prefixed with `_` even though they're public to avoid
* clashes with resource-related functions.
*
@shesek
shesek / Toodledo.php
Created July 27, 2011 15:02
Toodledo PHP API
<?php
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details. */
// Written by Shesek, http://www.shesek.info/php/toodledo-api
class Toodledo {
@shesek
shesek / setDefault.js
Created July 30, 2011 11:19
JavaScript default arguments
window.setDefault = function (args) {
for (var i = args.length + 1; i<arguments.length; i++) {
args[i-1] = arguments[i];
}
};
@shesek
shesek / i18n.coffee
Created November 14, 2011 22:38 — forked from madrobby/i18n.coffee
i18n with CoffeeScript
# Works with `global` instead of `window` when available (nodejs environment), no Backbone dependency,
# no ev[ai]l for rendering variables and a shorter `{...}` syntax.
(global or window).t = (id, vars = {}) ->
(i18n[__locale][id] or i18n.en[id] or "(?) #{id}")
.replace /\{(\w+)\}/g, (a, k) -> vars[k] or "?#{k}"
###
i18n=
@shesek
shesek / gist:1444629
Created December 7, 2011 21:00
CS stuff
_ = require 'underscore'
{Assign, Value, Literal, Access, Block, Class, Op, Obj, Arr, For, Index, Call, Return, If, Throw} = nodes = require '../nodes'
exports.originals = originals = {}
exports.codeblock = codeblock = (block) ->
return block unless block?
if typeof block is 'function'
@shesek
shesek / inject.coffee
Created February 11, 2012 04:10
Executing code in the webpage context from Chrome extensions.
inject = (args..., fn) ->
script = document.createElement 'script'
script.innerHTML = """
Array.prototype.pop.call(document.getElementsByTagName('script')).innerText = JSON.stringify(function() {
try { return #{ fn.toString() }.apply(window, #{ JSON.stringify args }); }
catch(e) { return {isException: true, exception: e.toString()}; }
}());
"""
document.body.appendChild script
response = JSON.parse script.innerText