Skip to content

Instantly share code, notes, and snippets.

View philipmat's full-sized avatar

Philip Mateescu philipmat

View GitHub Profile
@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 / PrefixInjecterTests.cs
Created September 28, 2015 20:44
PrefixInjection for ValueInjecter
using FluentAssertions;
using NUnit.Framework;
using Omu.ValueInjecter;
namespace ValueInjecter.Injecters
{
[TestFixture]
public class PrefixInjectionTests
{
private MySource _source;
@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 / 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
@philipmat
philipmat / gist:3695638
Created September 11, 2012 03:03
Kendo Combo Editor
// with <div id="grid"></div>
var sourceData = [
{ Position: 'One', Simple: 'foo', Complex: { Login: 'foo', Description: 'foo - Foo Frye' } },
{ Position: 'Two', Simple: 'bar', Complex: { Login: 'bar', Description: 'bar - Bar River' } },
{ Position: 'Three', Simple: 'bar', Complex: { Login: 'bar', Description: 'bar - Bar River' } },
{ Position: 'Four', Simple: 'baz', Complex: { Login: 'baz', Description: 'baz - Jayne Baz' } },
];
var nameList = [
-- Set this script as the script to run when a DVD is inserted into the player
property choiceButtons : {"Cancel", "Now", "Later"}
property defaultButton : "Later"
property giveUpAfter : 30
property player : "VLC"
-- property player:"DVD Player" -- the built-in DVD player
@philipmat
philipmat / bofh.rb
Created November 3, 2012 06:53
BOFH Excuse Generator
#!/usr/bin/ruby
part1 =
["Temporary", "Intermittant", "Partial", "Redundant", "Total", "Multiplexed",
"Inherent", "Duplicated", "Dual-Homed", "Synchronous", "Bidirectional",
"Serial", "Asynchronous", "Multiple", "Replicated", "Non-Replicated",
"Unregistered", "Non-Specific", "Generic", "Migrated", "Localised",
"Resignalled", "Dereferenced", "Nullified", "Aborted", "Serious", "Minor",
"Major", "Extraneous", "Illegal", "Insufficient", "Viral", "Unsupported",
"Outmoded", "Legacy", "Permanent", "Invalid", "Deprecated", "Virtual",
"Unreportable", "Undetermined", "Undiagnosable", "Unfiltered", "Static",