Skip to content

Instantly share code, notes, and snippets.

View socket_wrap_with_buffer.js
const { Socket } = require('net');
const { Duplex } = require('stream');
class JsonSocket extends Duplex {
JsonSocket implements a basic wire-protocol that encodes/decodes
JavaScripts objects as JSON strings over the wire. The wire protocol
is defined as:
4 len - length of JSON body
* Usage: Call BigAutorelease* a = create_autorelease_object();. If the dealloc message is not printed, this code is not running in an autorelease pool block.
@interface BigAutorelease: NSObject
@property(strong, nonatomic) NSMutableArray *arr;
@implementation BigAutorelease
- (instancetype)init {
NSLog(@"Make BigAutorelease");
# Find sqrt(2)
# Get a graph of y^2 - 2, find the 0. Use newtons's method.
import math
def iterate_root(start, n, p):
dx = .01
dy = ((start + dx) ** p) - (start ** p)
return start - ((start**p) - n)/(dy/dx)
def get_sqrt(n):
# Q: Given a list of length n+1 with numbers from 1 to n, there will be at least one duplicate. Find it.
# Running time: O(n). Space: O(1). Or rigorously O(lgn) given that a constant variable to represent the number "n" grows with lgn.
import random
import pytest
def find_dup(lst):
assert(len(lst) >= 2)
assert(all(map(lambda x: 0 < x < len(lst), lst)))
#find cycle
View makefile
# Makefile tutorial, through examples
# This is not a makefile! I just called it as such to have vim coloring work well.
# This makefile will always run. The default target is some_binary, because it is first.
echo "nothing"
View designer.html
<link rel="import" href="../code-mirror/code-mirror.html">
<link rel="import" href="../speech-mic/speech-mic.html">
<link rel="import" href="../yt-video/yt-search-video.html">
<link rel="import" href="../cool-clock/cool-clock.html">
<link rel="import" href="../paper-radio-button/paper-radio-button.html">
<polymer-element name="my-element">
theicfire / gist:8535877
Created Jan 21, 2014
Hide Old Rows for Google Docs using Apps Script
View gist:8535877
* Looks for rows with old dates, and hides them if so.
* It finds the date column my checking the first column for the word 'Date'.
function hideOldRows(colNum) {
var sheet = SpreadsheetApp.getActiveSheet();
var header = sheet.getRange(1, 1, 1, sheet.getLastColumn());
var colNum = header.getValues()[0].indexOf('Date') + 1;
if (colNum === 0) {
theicfire / gist:6573314
Last active Dec 23, 2015
Resizable line with handles | SVG, d3.js, Javascript
View gist:6573314
<!DOCTYPE html>
<meta charset="utf-8">
svg {
float: left;
line {
shape-rendering: crispEdges;
stroke-width: 1px;
theicfire /
Created Aug 11, 2012 — forked from josephwecker/
Replace .bashrc, .bash_profile, .profile, etc. with something much more clean, consistent, and meaningful.
# License: Public Domain.
# Author: Joseph Wecker, 2012
# Are you tired of trying to remember what .bashrc does vs .bash_profile vs .profile?
# Are you tired of trying to remember how darwin/mac-osx treat them differently from linux?
# Are you tired of not having your ~/.bash* stuff work the way you expect?
# Symlink all of the following to this file:
# * ~/.bashrc