Skip to content

Instantly share code, notes, and snippets.

View treble37's full-sized avatar
🏠
Working from home

Bruce Park treble37

🏠
Working from home
View GitHub Profile
@treble37
treble37 / active_record_objects_autosave.md
Created June 2, 2016 21:03 — forked from demisx/active_record_objects_autosave.md
When Active Record Child Objects are Autosaved in Rails

belongs_to:

  1. Assigning an object to a belongs_to association does not automatically save the object. It does not save the associated object either.

has_one:

  1. When you assign an object to a has_one association, that object is automatically saved (in order to update its foreign key).
  2. In addition, any object being replaced is also automatically saved, because its foreign key will change too
  3. If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
  4. If the parent object (the one declaring the has_one association) is unsaved (that is, new_record? returns true) then the child objects are not saved. They will automatically when the parent object is saved.
@treble37
treble37 / hstore_pivot.sql
Created May 11, 2016 22:09 — forked from gurix/hstore_pivot.sql
Creating a cross tab / pivot table form hstore fields with dynamical column names using in postgresql
DROP TABLE IF EXISTS survey_sessions;
-- Imagine a table with survey sessions
-- token: some id or token to access a survey
-- answers: a key value store for answers
CREATE TABLE survey_sessions (
token text,
answers hstore);
-- We need some data to play with
INSERT INTO survey_sessions (token, answers) VALUES ('9IaxxP', 'a=>1, b=>2');
@treble37
treble37 / 01. Gemfile
Created January 20, 2016 01:37 — forked from schleg/01. Gemfile
Setup for Devise + Omniauth
gem 'pg'
group :development do
gem 'ruby-debug'
end
gem 'rake', '~> 0.8.7'
gem 'devise'
gem 'oa-oauth', :require => 'omniauth/oauth'
gem 'omniauth'
gem 'haml'
gem 'dynamic_form'
@treble37
treble37 / 00.howto_install_phantomjs.md
Created October 8, 2015 21:17 — forked from julionc/00.howto_install_phantomjs.md
How to install PhantomJS on Debian/Ubuntu

How to install PhantomJS on Ubuntu

Version: 1.9.8

Platform: x86_64

First, install or update to the latest system software.

sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev
<?php
/*
Template Name: Landing
*/
// Add custom body class to the head
add_filter( 'body_class', 'add_body_class' );
function add_body_class( $classes ) {
$classes[] = 'landing-page';
@treble37
treble37 / integer.rb
Last active August 29, 2015 14:15 — forked from pithyless/integer.rb
class Integer
N_BYTES = [42].pack('i').size
N_BITS = N_BYTES * 16
MAX = 2 ** (N_BITS - 2) - 1
MIN = -MAX - 1
end
p Integer::MAX #=> 4611686018427387903
p Integer::MAX.class #=> Fixnum
p (Integer::MAX + 1).class #=> Bignum
@treble37
treble37 / step3-testing-elasticsearch-posts_spec.rb
Created February 3, 2015 05:57
Step 3 - Testing ElasticSearch - posts_spec.rb
require 'spec_helper'
require 'rake'
RSpec.describe Api::V1::PostsController, :vcr, record: :new_episodes, :type => :api do
context "elastic search test", elasticsearch: true, commit: true do
before do
@post = FactoryGirl.create(:post, first_name: "August", last_name: "Rush", email: "[email protected]", event: "Rock Concert")
end
@treble37
treble37 / step2-testing-elasticsearch-database_cleaner.rb
Created February 3, 2015 05:51
Step 2 - Testing ElasticSearch - database_cleaner.rb
RSpec.configure do |config|
#config.before(:suite) do
# DatabaseCleaner.clean_with(:truncation)
#end
#config.before(:each) do
# DatabaseCleaner.strategy = :transaction
#end
@treble37
treble37 / step1-testing-elasticsearch.rb
Created February 3, 2015 05:46
Step 1 - Testing ElasticSearch - spec_helper.rb
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause this
# file to always be loaded, without a need to explicitly require it in any files.
#
# Given that it is always loaded, you are encouraged to keep this file as
# light-weight as possible. Requiring heavyweight dependencies from this file
# will add to the boot time of your test suite on EVERY test run, even for an
# individual file that may not need all of that loaded. Instead, make a
# separate helper file that requires this one and then use it only in the specs

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname