Skip to content

Instantly share code, notes, and snippets.

View jyzhang's full-sized avatar

James Zhang jyzhang

View GitHub Profile
# model style guide
class ModelX < ActiveRecord::Base
# 1. include mixins here
include BT::Token
# 2. constants
Timeout = 1.day
Status = OpenStruct.new(active: 0, disabled: -1).freeze
# 3. associations
# 3a. belongs_to
@jyzhang
jyzhang / elements.js
Last active August 29, 2015 14:09
jQuery Cheat Sheet
// manipulating values and attributes
$("div.foo").html(); // getter
$("div.foo").html("<h1>Hello World</h1>"); // setter
$("div.foo").text(); // getter, strips html
$("div.foo").text("hello world"); // setter
$("a.foo").attr("class"); // getter
$("a.foo").attr("href", "foo.html"); // setter
StringBuilder sb = new StringBuilder();
String msg = sb.append("Error in: ").append(getClass().getSimpleName()).append(" -- ").append(e.getMessage()).toString();
String temp1 = "Error in: " + getClass().getSimpleName();
String temp2 = temp1 + " -- ";
String msg = temp2 + e.getMessage();
String msg = "Error in: " + getClass().getSimpleName() + " -- " + e.getMessage();
@jyzhang
jyzhang / StringConcat.java
Created July 17, 2012 00:24
Benchmark string concatenation (version 2)
package com.bluetornadosf.microbench;
import java.util.HashMap;
import org.apache.commons.lang3.RandomStringUtils;
import com.google.caliper.Runner;
import com.google.caliper.SimpleBenchmark;
public class StringConcat extends SimpleBenchmark {
@jyzhang
jyzhang / StringConcat.java
Created July 17, 2012 00:23
Benchmark string concatenation (version 1)
import java.util.HashMap;
import org.apache.commons.lang3.RandomStringUtils;
import com.google.caliper.Runner;
import com.google.caliper.SimpleBenchmark;
public class StringConcat extends SimpleBenchmark {
private final static int CONCATENATIONS = 5;