Skip to content

Instantly share code, notes, and snippets.

@weilu
weilu / 0_reuse_code.js
Created March 18, 2014 05:42
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@weilu
weilu / expressParseCookie.js
Created June 11, 2014 01:57
express.js: test cookie content
var cookieParser = require('express').cookieParser(process.env.COOKIE_SALT)
function parseCookie(cookie){
var fakeReq = {headers: {cookie: cookie}}
cookieParser(fakeReq, null, function(){
console.log(fakeReq)
})
}
parseCookie("connect.sid=s%3A70TTUUz60sHREcMcDsBuTWBf.2vKZjdW%2B2ecr%2Bk8kI%2Frno%2BoqdQmSPHFuz1g4V7OJzSM; Path=/; HttpOnly")
@weilu
weilu / semver-ranges.md
Last active August 29, 2015 14:03
Much Semver, Such Confusion

Rubygem's ~> pessimistic / eat beacon / spermy operator

Keep first n-1 digits the same, last digit is free to increment to some arbitrary value

~>1:      >=1.0.0 <2.0.0
~>1.0:    >=1.0.0 <2.0.0
~>1.2.3:  >=1.2.3 <1.3.0
~>0.1:    >=0.1.0 <1.0.0
~&gt;0.1.3: &gt;=0.1.3 &lt;0.2.0
@weilu
weilu / edit_post_spec.rb
Created November 5, 2012 13:03
Turn off transactional fixtures only for Capybara javascript specs
# requests/edit_post_spec.rb
require 'spec_helper'
feature 'editing a post', js: true do
let(:post) { create :post }
let(:user) { post.creator }
before { sign_in user }

Definitely

  • Have professors help with the publicity
  • Keep workshop interactive
  • More variety of drinks
  • Spend more time on Koans
  • Provide vegan options for lunch
  • Introduce handy standarded lib functions
  • Bring Neo banner along
  • Make sure venue has pairing-friendly tables
import java.util.*;
class Programmer {
private String name;
private int age;
private List<String> languages;
public Programmer(String name) {
this.name = name;
this.languages = new ArrayList<String>();
@weilu
weilu / Cheffile
Last active December 18, 2015 09:39 — forked from neo-common/Cheffile
site 'http://community.opscode.com/api/v1'
cookbook 'sprout-osx-base',
:git => 'git://github.com/pivotal-sprout/sprout.git',
:path => 'sprout-osx-base'
cookbook 'pivotal_workstation',
:git => 'git://github.com/pivotal-sprout/sprout.git',
:path => 'pivotal_workstation'

The Problem

Standard practices say no non-root process gets to talk to the Internet on a port less than 1024. How, then, could I get Node talking on port 80 on EC2? (I wanted it to go as fast as possible and use the smallest possible share of my teeny tiny little micro-instance's resources, so proxying through nginx or Apache seemed suboptimal.)

The temptingly easy but ultimately wrong solution:

Alter the port the script talks to from 8000 to 80:

}).listen(80);
@weilu
weilu / null.sql
Created October 16, 2013 02:09
PostgreSQL NULL comparison
=# select (1!=1);
?column?
----------
f
(1 row)
=# select (1=1);
?column?
----------
t
require "active_record"
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Schema.define do
create_table :languages do |t|
t.string :type
end
end