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 / 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
<?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 / 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
@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 / 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 / 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 / gist:2faf39df359b608765560e85032d9fab
Created June 28, 2016 17:37 — forked from alex-zige/gist:5795358
Rails Rspec API Testing Notes

Rails Rspec APIs Testing Notes

Folders Structure

  spec
  |--- apis #do not put into controllers folder. 
        |--- your_api_test_spec.rb  
  |--- controllers
  |--- models
  |--- factories
 |--- views
@treble37
treble37 / post.md
Created September 13, 2016 00:31 — forked from fxn/post.md
GeoPlanet data with ancestor chain cache imported in 10 minutes

GeoPlanet data with ancestor chain cache imported in 10 minutes

Yahoo! provides its GeoPlanet data as three separate TSV files, available for download here.

That's a database with some 17 million records:

  • 5.7 million records: locations (aka places).
  • 2.2 million records: alternative names for each place (aka aliases).
  • 9.6 million records: matrix of neighbourhoods per place (aka adjacencies).
@treble37
treble37 / Algorithms: Design and Analysis, Part 2.md
Created September 13, 2016 05:06 — forked from misho-kr/Algorithms: Design and Analysis, Part 2.md
Summary of "Algorithms: Design and Analysis, Part 2" course at Coursera.Org

The course will have six weeks of lectures and assignments, followed by a final exam.

Week 1

I. TWO MOTIVATING APPLICATIONS

  • Distributed shortest-path routing -- sending email messages
@treble37
treble37 / presenters.md
Last active November 15, 2021 12:21 — forked from somebox/presenters.md
Thoughts About Rails Presenters