Skip to content

Instantly share code, notes, and snippets.

@bbugh
bbugh / rvm-sublime-text-2.md
Last active August 29, 2015 13:57
Using RVM in Sublime Text 2

Start with:

subl ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/Ruby/Ruby.sublime-build

Copy and paste this, replacing the contents of that file with this:

{
  "env":{
 "PATH":"${HOME}/.rvm/bin:${PATH}"
@bbugh
bbugh / jquery-practice
Created December 7, 2014 18:27
Practicing events with jQuery
<!DOCTYPE html>
<html lang="en">
<head>
<title>jQuery Practice</title>
</head>
<body>
<div id="content">
<div class="entry">
<h1>You Won't Believe What Happens When You Click This Link</h1>
<a href="#">Click me!</a>
@bbugh
bbugh / gist:3842793
Created October 5, 2012 22:21
Automatically stripping/highlighting trailing whitespace in VIM
" Two best solutions from the discussion here http://stackoverflow.com/questions/356126/how-can-you-automatically-remove-trailing-whitespace-in-vim
" Automatically strip white space on save in VIM.
fun! <SID>StripTrailingWhitespaces()
let l = line(".")
let c = col(".")
%s/\s\+$//e
call cursor(l, c)
endfun
@bbugh
bbugh / gist:3880669
Created October 12, 2012 18:22
Displaying unpushed changes on branches in git
@bbugh
bbugh / gist:3907096
Created October 17, 2012 18:06
Drop and recreate test database

I would recommend dropping your test database, then re-create it and migrate:

bundle exec rake db:drop RAILS_ENV=test
bundle exec rake db:create RAILS_ENV=test
bundle exec rake db:schema:load RAILS_ENV=test

Shorter:

@bbugh
bbugh / gist:4657749
Created January 28, 2013 18:14
Using traits in FactoryGirl to do things like add tags to models, or unassociated data that multiple models would share.

Using traits in FactoryGirl for things like tags on other models, and so forth.

FactoryGirl.define do
  factory :post do
    title 'New post'
  end

  trait :with_comments do
 after :create do |post|
@bbugh
bbugh / gist:5207416
Created March 20, 2013 18:57
Creating a valid email address from a name and email, using the Ruby Mail library. Used to prevent invalid headers.

If you are taking user input for name and email, then unless you very carefully validate or escape the name and email, you can end up with an invalid From header by simply concatenating strings. Here is a safe way:

require 'mail'
address = Mail::Address.new email # ex: "john@example.com"
address.display_name = name # ex: "John Doe"
# Set the From or Reply-To header to the following:
address.format # returns "John Doe <john@example.com>"
# Elixir solution for http://www.codewars.com/kata/dont-drink-the-water
defmodule Liquids do
@density %{ ?H => 1.36, ?W => 1.00, ?A => 0.87, ?O => 0.8 }
def separate_liquids([]), do: []
def separate_liquids([h|_] = glass) when is_list(h) and length(h) > 0 do
List.flatten(glass) |> Enum.sort_by(&(@density[&1])) |> Enum.chunk(length(h))
end
end
@bbugh
bbugh / introrx.md
Last active March 12, 2016 18:43 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called Reactive Programming, particularly its variant comprising of Rx, Bacon.js, RAC, and others.

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

@bbugh
bbugh / ipython_magic_function_inspector.py
Last active December 17, 2016 00:46
iPython Django extensions
"""
An IPython magic function to pretty-print objects with syntax highlighting.
Updated to also pretty print the object's __dict__ if it's available.
See, "Defining your own magics":
http://ipython.org/ipython-doc/stable/interactive/reference.html#defining-your-own-magics
For more on Pygments:
http://pygments.org/docs/quickstart/
Usage