Skip to content

Instantly share code, notes, and snippets.

View tb's full-sized avatar
🚀
Building High-Performing Software Engineering Teams

Tomasz Bak tb

🚀
Building High-Performing Software Engineering Teams
View GitHub Profile
@tb
tb / gist:1053722
Created June 29, 2011 12:18
Presenter classes pattern in Rails
http://assets.en.oreilly.com/1/event/59/Fat%20Models%20Aren_t%20Enough%20Presentation.pdf
http://stackoverflow.com/questions/2822314/about-presenter-pattern-in-rails-is-a-better-way-to-do-it/2822836#2822836
http://donttrustthisguy.com/2008/05/29/using-presenters-in-rails-3/
@tb
tb / jquery.ba-tinypubsub.min.js
Created December 2, 2012 20:45 — forked from ukw-snippets/jquery.ba-tinypubsub.min.js
Javascript: Tiny Pub/Sub / Observer
/* jQuery Tiny Pub/Sub - v0.7 - 10/27/2011
* http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
(function($) {
var o = $({});
$.subscribe = function() {
o.on.apply(o, arguments);
require 'singleton'
# outputs a colored call-trace graph to the Rails logger of the lines of ruby code
# invoked during a single request.
#
# Example:
#
# 1) Make sure this file is loaded in an initializer
#
# 2) Add the following to your application.rb in Rails3:
namespace :server_db do
task :get, :roles => :app do
puts "This task is designed to get database from the server"
puts "Example: cap ENV server_db:get"
timestamp = Time.new.strftime("%Y-%m-%d-%H%M%S")
tmp_dir = '~/tmp'
db_name = "viclarity_#{rails_env}"
db_dump = "#{db_name}_#{timestamp}"
db_dump_gz = "#{tmp_dir}/#{db_dump}.gz"
Install Java JDK 6.0 update 31 on Ubuntu 12.04 LTS
Introduction
The first question is why are we installing an old JDK. The answer is that Oracle JDK 6.0 update 31 is the JDK recommended by Cloudera when installing CDH4 (Cloudera Distribution Hadoop v4).
This is an update to an older version of this post. Mainly I have changed the JDK from 1.6.0_26 to 1.6.0_31 as this is the recommended JDK for CDH4 .
Install Java
I have a 64 bit version of Ubuntu 12.04 LTS installed, so the instructions below only apply to this OS.
# When an RSpec test like this fails,
#
# @my_array.should == [@some_model, @some_model2]
#
# RSpec will call inspect on each of the objects to "help" you figure out
# what went wrong. Well, inspect will usually dump a TON OF SHIT and make trying
# to figure out why `@my_array` is not made up of `@some_model` and `@some_model2`
# really really painful.
#
# This little module and technique helps get around that. It will redefine `inspect`
@tb
tb / working_url.rb
Last active December 1, 2020 19:53
Check if URL exists in Ruby
require 'net/http'
def working_url?(url_str)
url = URI.parse(url_str)
Net::HTTP.start(url.host, url.port) do |http|
http.head(url.request_uri).code == '200'
end
rescue
false
end
echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.3 postgresql-server-dev-9.3 postgresql-contrib-9.3 -y
sudo su - postgres -c "psql template1 -p 5433 -c 'CREATE EXTENSION IF NOT EXISTS hstore;'"
sudo su - postgres -c "psql template1 -p 5433 -c 'CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";'"
sudo su - postgres -c "service postgresql stop"
sudo su - postgres -c '/usr/lib/postgresql/9.3/bin/pg_upgrade -b /usr/lib/postgresql/9.1/bin -B /usr/lib/postgresql/9.3/bin -d /var/lib/postgresql/9.1/main/ -D /var/lib/postgresql/9.3/main/ -O "-c config_file=/etc/postgresql/9.3/main/postgresql.conf" -o "-c config_file=/etc/postgresql/9.1/main/postgresql.conf"'
require 'RMagick'
require 'capybara'
require 'launchy'
module Capybara::Recording
def start_recording
system "rm -f tmp/*"
end
def save_recording
(function() {
"use strict";
angular.module("editableModule", ['ng']).directive("editable", function($timeout) {
return {
restrict: "AE",
scope: true,
require:"ngModel",
link: function(scope, element, attrs, ngModel) {
element.editable({