Skip to content

Instantly share code, notes, and snippets.

View philipmat's full-sized avatar

Philip Mateescu philipmat

View GitHub Profile
@philipmat
philipmat / gist:1196552
Created September 6, 2011 04:05
Books24x7 page cleanup
d = document;
function p(n){return n.parentNode}
function $(x){return d.getElementById(x)}
function $t(x){return d.getElementsByTagName(x)}
function $c(x){return d.getElementsByClassName(x)}
function $r(n){p(n).removeChild(n)}
if (d.location.href.indexOf('mobile.books24x7') != -1 ) {
while($t('link').length != 1) {
l = $t('link');
for(var i = 0; i < l.length; i++) if (l[i].href.indexOf('grison') == -1) $r(l[i]);
@philipmat
philipmat / gist:1202891
Created September 8, 2011 08:08
npm update -g
# npm update -g -ddd
npm info it worked if it ends with ok
npm verb cli [ 'node',
npm verb cli '/usr/local/bin/npm',
npm verb cli 'update',
npm verb cli '-g',
npm verb cli '-ddd' ]
npm info using npm@1.0.27
npm info using node@v0.5.5
npm verb /usr/local/bin/node node symlink
@philipmat
philipmat / transmission_cli.sh
Created September 14, 2011 03:57
transmission cli for freenas
#!/bin/bash
# filename: transmission_cli_manager.sh
# author: Dan Merschi
# date: 2009-01-17 (0.69 rev.4260)
# update: 2009-03-01 (0.69 rev 4403)
# purpose: A fast and easy solution(script) to manage Transmission daemon via transmission-remote client
# source: http://sourceforge.net/apps/phpbb/freenas/viewtopic.php?f=12&t=822
#
if [ -z "$(pgrep transmission-daemon)" ] ;then echo Transmission not running, abort.; exit 3; fi
eval $( ps axww | \
@philipmat
philipmat / asynceventemitter.coffee
Created October 8, 2011 05:28
AsyncEventEmitter
class AsyncEventEmitter
constructor : () ->
@_dict = {}
emit : (eventName, args...) ->
if @_dict[eventName]?
(process.nextTick () ->
callback.apply null, args) for callback in @_dict[eventName]
once : (eventName, callback) ->
@philipmat
philipmat / inc.js
Created October 9, 2011 15:38
Benchmarking node
var MAX = 1E8;
function out(i, final, res) {
res.end(i + "+1 " + MAX + " times = " + final + "\n");
}
var inc_sync = function (i, callback) {
var k = 0, x = i;
for(var k = 0; k < MAX; k++)
x += 1;
callback(i, x);
@philipmat
philipmat / Binding#FormatObject.cs
Created October 13, 2011 06:39
DataBinding errors with interfaces
...
private object FormatObject(object value)
{
if (this.ControlAtDesignTime())
return value;
System.Type propertyType = this.propInfo.PropertyType;
if (this.formattingEnabled)
{
ConvertEventArgs cevent = new ConvertEventArgs(value, propertyType);
@philipmat
philipmat / (win) Session.vim
Created December 6, 2011 09:21
Vim session with set sessionoptions="buffers,sesdir,folds,tabpages"
let SessionLoad = 1
if &cp | set nocp | endif
let s:so_save = &so | let s:siso_save = &siso | set so=0 siso=0
let v:this_session=expand("<sfile>:p")
silent only
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
let s:wipebuf = bufnr('%')
endif
set shortmess=aoO
badd +2 C:\temp\file1.txt
@philipmat
philipmat / MacKeyMap.ahk
Created January 5, 2012 18:01
Mac-like keyboard map for AutoHotKey
#SingleInstance force
; Revert mouse direction
#MaxHotkeysPerInterval 400
WheelDown::WheelUp
WheelUp::WheelDown
; Remap capslock to control
Capslock::Ctrl
; Alternative - get a Win key back
; Capslock::Win
@philipmat
philipmat / custom_maps.vim
Created February 15, 2012 11:01 — forked from scrooloose/custom_maps.vim
Couple of custom key maps for nerdtree
if exists("g:loaded_nerdtree_custom_maps")
finish
endif
let g:loaded_nerdtree_custom_maps = 1
"adds a new keymapping on 'gT' that opens the selected file in a bg tab and
"closes the tree
call NERDTreeAddKeyMap({
\ 'scope': 'FileNode',
\ 'key': 'T',
@philipmat
philipmat / json_entity_converter.cs
Created February 20, 2012 10:17
JSON Entity Converter
void Main()
{
var co = new Company { Id = 1, Name = "Moof Inc." };
var clarus = new Contact { Id = 1, Name = "Clarus" };
var mark = new Contact { Id = 2, Name = "Mark" };
co.AddContact(clarus);
co.AddContact(mark);
co.MainContact = clarus;
// Attempt #1: Straight up, no converter