Skip to content

Instantly share code, notes, and snippets.

View Sannis's full-sized avatar
🎯
Focusing

Oleg Efimov Sannis

🎯
Focusing
View GitHub Profile
Buffer.prototype.pprint = function() {
var line = "";
if(this.length > 0) {
for(var i=0; i<this.length; i++) {
if(i%8==0) {
sys.print(" ");
}
if(i%16==0) {
sys.print(line);
line = "";
@xavi-
xavi- / gist:633087
Created October 18, 2010 21:21 — forked from jimbojw/gist:583389
Interview gist -- Can candidate read, debug, and fix code?
// For each of the following code fragments:
// a. what does the code do?
// b. what did the author intend for it to do?
// c. how would you fix it?
// NOTE: all code samples work exactly the same in all browsers
// 1. object literals
var data = [ { high: 100, low: 81 }, { high: 93, low: 73 }, { high: 60, low: 32 } ];
function getAverages(data) {
var avgs = [];
@xavi-
xavi- / gist:633341
Created October 19, 2010 00:15
Interview gist -- Can candidate write code?

Instructions

  • Solve all problems using JavaScript

Problems

  1. Write a function that returns an array with the first n powers of 2. Call it twoPow.

  2. Use twoPow and Array.prototype.reduce to the sum of the first 10 powers of 2.

  3. Describe this call signature:

@joekim
joekim / json-protocol.js
Created December 7, 2011 03:12
A simple carriage-return, line-feed delimited JSON protocol.
/*
A simple newline delimited JSON protocol.
Receiving Usage:
protocol = require('./json-protocol');
// parsing data
parser = protocol.StreamParser();
@DavertMik
DavertMik / gist:1936860
Created February 29, 2012 01:40
Dependency Management Concept. RFC

This is about getting rid of Dependency Injection Container and DI practices taken from Java. Good bye Java, viva la PHP!

We start with common example. Session.

<?php

class SessionStorage {

 	function __construct() 
@Sannis
Sannis / screencast.sh
Created March 15, 2012 21:22 — forked from pomeo/screencast.sh
script to make screencasts on Linux
#!/bin/bash
# list of programs we depend on
progs="xdpyinfo grep head sed ffmpeg pacat parec sox"
# check for programs we depend on
result=0
for prog in $progs
do
type -p $prog > /dev/null
@oleics
oleics / moduleofmodule.js
Created June 28, 2012 15:03
module of module
var foo = require('./foo')
, barOfFoo = moduleOfModule('./bar', './foo')
function moduleOfModule(module, ofModule) {
var c = require.cache[require.resolve(ofModule)]
, f = require.resolve(module, c)
, r
c.children.some(function(c) {
if(c.filename === f) {
r = c.exports
@sirmax
sirmax / fix-wifi.sh
Last active December 11, 2015 15:28
#! /usr/bin/env bash
function nEnabled {
system_profiler -detailLevel mini SPAirPortDataType | grep -e 'Supported PHY Modes: .*n'
}
until nEnabled && sleep 2 && nEnabled;
do
echo 'resetting airport'
networksetup -setairportpower en1 off; networksetup -setairportpower en1 on
@mikeal
mikeal / gist:2504336
Created April 27, 2012 00:11
Date parsing JSON
JSON._dateReviver = function (k,v) {
if (v.length !== 24 || typeof v !== 'string') return v
try {return new Date(v)}
catch(e) {return v}
}
JSON.parseWithDates = function (obj) {
return JSON.parse(obj, JSON._dateReviver);
}
@TooTallNate
TooTallNate / README.md
Created November 16, 2011 00:57
A C header file to make your node bindings backwards and forwards compatible that use eio_custom()

node_async_shim.h

Use this header file to conditionally invoke eio_custom() or uv_queue_work(), depending on the node version that the module is being compiled for.

See the usage.cc file for a partial example.

Comments, forks, and improvements are welcome!