Skip to content

Instantly share code, notes, and snippets.

@just3ws
just3ws / gist:571288
Created September 9, 2010 03:06
A really crappy implementation of a before/after actions using the Using() keyword in C#
//This work licensed under the WTFPL License
//WTFPL: http://sam.zoy.org/wtfpl/.
using System;
namespace EntryExitThing
{
internal class Program
{
/// <summary>
/// Entrypoint for the application.
# clear; spec spec/models/user_spec.rb -f specdoc --colour
require 'spec/spec_helper'
describe User, "add reputation via voting" do
let(:user) {User.new}
context "when starting from a brand new user" do
it "gives a user one reputation for free" do
user.reputation.should equal 1
@just3ws
just3ws / Unable to install packages with RVM
Created February 6, 2011 00:44
Unable to install packages with RVM
just3ws:~ mdh$ uname -a
Darwin just3ws.local 10.6.0 Darwin Kernel Version 10.6.0: Wed Nov 10 18:11:58 PST 2010; root:xnu-1504.9.26~3/RELEASE_X86_64 x86_64
just3ws:~ mdh$ echo $ARCHFLAGS
-arch x86_64
just3ws:~ mdh$ rvm package install zlib
Fetching zlib-1.2.5.tar.gz to /Users/mdh/.rvm/archives
@just3ws
just3ws / Gem list
Created March 16, 2011 12:54
RSpec fails when run via 'rake' but works as expected when run alone or via bundle exec spec.
abstract (1.0.0)
actionmailer (3.0.5)
actionpack (3.0.5)
activemodel (3.0.5)
activerecord (3.0.5)
activeresource (3.0.5)
activesupport (3.0.5)
annotate (2.4.0)
arel (2.0.9)
autotest-fsevent (0.2.5)
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
[[ -r $rvm_path/scripts/completion ]] && . $rvm_path/scripts/completion
export PATH=$rvm_path/bin:$PATH
@just3ws
just3ws / Refactored.js
Created April 14, 2011 17:55
Toggles elements by their title as characters are typed into the text box.
// The character array as a queue was clever but poorly implemented and unnecessary.
// Instead, just read the query from the input.
// Also handles mouse driven content actions (cut, paste, etc).
$(function() {
var filter = function(query) {
var titlesSelector = "#content .show h3 a";
if (query == '') {
$(titlesSelector).closest(".show").show();
} else {
@just3ws
just3ws / Something like this.txt
Created March 20, 2012 18:15
Pushing testing tools into a sub-directory
MyAppRoot/
├── lib
└── tests
├── .simplecov
├── .rspec
├── config
├── features
├── fixtures
│   └── data.yml
└── specs
# 1) Take any 3 digit number, But the first and third number Cannot be the same.
# 2) reverse the order and subtract
# 3) reverse the answer and then add it
"1234567890"
.split(//)
.map {|i| i.to_i }
.permutation(3)
.to_a
.map {|n| [n, n.reverse] }
@just3ws
just3ws / fucking_twitter.rb
Created December 4, 2012 17:10
Because Twitter eats whitespace...
# The example I tweeted about preferring the more verbose if..then..else..end
# over ternary operations in Ruby got mangled by Twitter.
# So when my tweet showed everything on one line my message got muddled.
# The reformatting of my tweet also looked like I was trying to evaluate
# an expression that returned literally "true" or "false" which wasn't the case.
# What I wanted to show was that many people write IF/ELSE statements as
# ternary operations.
@just3ws
just3ws / models_and_controllers_helpers.rb
Last active December 10, 2015 07:18
Rails console helpers to put in your .irbrc that will return an array of AR model constants and an array of controller constants respectively.
def self.models
ActiveRecord::Base
.send(:subclasses)
.map { |model| model.name.constantize }
end
def self.controllers
Rails.application.routes.routes
.select { |r| r.defaults[:controller].present? }
.uniq { |r| r.defaults[:controller] }