Skip to content

Instantly share code, notes, and snippets.

@wbzyl
wbzyl / active_record_associations.rb
Created July 30, 2012 18:08 — forked from karmi/active_record_associations.rb
An example of elasticsearch & Tire setup for ActiveRecord associations
# An example of elasticsearch & Tire setup for ActiveRecord associations.
#
# A `Book has_many :chapters` scenario, with mapping and JSON serialization
# for indexing associated models.
#
# Demonstrates three important caveats as of now:
#
# 1. You you have to use `touch: true` in the `belongs_to` declaration,
# to automatically notify the parent model about the update.
#

Sass/Less Comparison

In this document I am using Sass's SCSS syntax. You can choose to use the indented syntax in sass, if you prefer it, it has no functional differences from the SCSS syntax.

For Less, I'm using the JavaScript version because this is what they suggest on the website. The ruby version may be different.

Variables

@wbzyl
wbzyl / .gitignore
Created September 4, 2012 19:53 — forked from karmi/.gitignore
World's Smallest Application Hosted in elasticsearch
.DS_Store
tmp/
@wbzyl
wbzyl / Gemfile
Created September 13, 2012 16:18
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
source :rubygems
# We are not loading Active Record, nor Active Resources etc.
# We can do this in any app by simply replacing the rails gem
# by the parts we want to use.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
gem "tzinfo"
# Let's use thin
@wbzyl
wbzyl / elasticsearch.rake
Created October 10, 2012 09:14 — forked from jarosan/elasticsearch.rake
Elasticsearch reindex task
# Run with: rake environment elasticsearch:reindex
namespace :elasticsearch do
desc "re-index elasticsearch"
task :reindex => :environment do
klass = Place
ENV['CLASS'] = klass.name
ENV['INDEX'] = new_index = klass.tire.index.name << '_' << Time.now.strftime('%Y%m%d%H%M%S')
#!/usr/bin/env ruby
#
# newrailsproject.rb
#
# Description:
# Easily create a new Rails project and Sublime Text 2 project file.
#
# By Jonathan Beebe. MIT License.
#
# Syntax: ruby newrailsproject.rb PROJECT_NAME BASE_PATH [sublime_project_basepath]
// make sure we're using the right db; this is the same as "use aggdb;" in shell
db = db.getSiblingDB("aggdb");
// simple projection
var p1 = db.runCommand(
{ aggregate : "article", pipeline : [
{ $project : {
tags : 1,
pageViews : 1
}}
var fs = require('fs');
var start_fs = (new Date()).getTime();
var data = fs.readFileSync('./100_log', 'utf-8');
var start = (new Date()).getTime();
var log = data.split('\n').map(function (line) {
var match = line.match(/\[([^\]]+)\] \[([^\]]+)\] \[([^ ]+) ([^\]]+)\] (.*)/);
upstream your-app {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response (in case the Unicorn master nukes a
# single worker for timing out).
server unix:/tmp/your_app.socket fail_timeout=0;
}
server {
listen 80;

Mathematics: What do grad students in math do all day?

by Yasha Berchenko-Kogan

A lot of math grad school is reading books and papers and trying to understand what's going on. The difficulty is that reading math is not like reading a mystery thriller, and it's not even like reading a history book or a New York Times article.

The main issue is that, by the time you get to the frontiers of math, the words to describe the concepts don't really exist yet. Communicating these ideas is a bit like trying to explain a vacuum cleaner to someone who has never seen one, except you're only allowed to use words that are four letters long or shorter.

What can you say?