Skip to content

Instantly share code, notes, and snippets.

@ChuntaoLu
ChuntaoLu / tree.md
Created March 8, 2014 19:48 — forked from hrldcpr/tree.md

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

require 'csv'
def memstats
size = `ps -o size= #{$$}`.strip.to_i
end
memstats #4900
CSV.open('visitors.csv', headers: true) do |csv|
visitors = csv.each # Enumerator
memstats # 5164
#! /bin/sh
alias gs="git status"
alias gc="git commit"
alias gr="git checkout"
alias ga="git add"
alias gl="git lola"
<% flash.each do |type, message| %>
<div class="alert <%= bootstrap_class_for(type) %> fade in">
<button class="close" data-dismiss="alert">×</button>
<%= message %>
</div>
<% end %>
inputs = %w[
CollectionSelectInput
DateTimeInput
FileInput
GroupedCollectionSelectInput
NumericInput
PasswordInput
RangeInput
StringInput
TextInput
describe "Shopping Cart Requests" do
let!(:user) { Fabricate(:user) }
before(:each) do
login_user_post("admin", "admin")
end
context "when I visit the shopping cart" do
it " show the logged in users' cart items " do
#Test stuff
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@ChuntaoLu
ChuntaoLu / uri.js
Created January 21, 2014 18:19 — forked from jlong/uri.js
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@ChuntaoLu
ChuntaoLu / module_pattern.js
Last active January 4, 2016 00:59
JavaScript module pattern: Function defines private variables and functions. Privileged functions can access private variables and functions via closure. The function returns the privileged functions or stores them in accessible place.
var serial_maker = function(){
// produce an object that produces unique strings.
var prefix = '';
var seq = 0;
return {
set_prefix: function (p) {
prefix = String(p);
},