Skip to content

Instantly share code, notes, and snippets.

View cemeng's full-sized avatar
💭
aw yis

Felix Tjandrawibawa cemeng

💭
aw yis
View GitHub Profile
@cemeng
cemeng / ruby_sublime_settings.json
Created August 1, 2011 03:45
Ruby Sublime Settings
// Settings in here override those in "Default/Base File.sublime-settings", and
// are overridden in turn by file type specific settings. Place your settings
// here, to ensure they're preserved when upgrading.
{
"tab_size": 2,
"translate_tabs_to_spaces": true,
"detect_indentation": true,
"use_tab_stops": true
}
@cemeng
cemeng / gist:1122488
Created August 3, 2011 12:10
unit test w/ webmock
require 'helper'
class TestDailymileRuby < Test::Unit::TestCase
def setup
WebMock.disable_net_connect!
end
should "be able to post a simple entry" do
# Stub setup
params = {
@cemeng
cemeng / Copying Ruby Array
Created October 27, 2011 09:31
Things that I learned about Ruby Array
ruby-1.9.2-p290 :032 > a = [ [1,2], [3,4] ]
=> [[1, 2], [3, 4]]
ruby-1.9.2-p290 :033 > b = a.dup
=> [[1, 2], [3, 4]]
ruby-1.9.2-p290 :034 > c = a.clone
=> [[1, 2], [3, 4]]
ruby-1.9.2-p290 :035 > d = Array.new(a)
=> [[1, 2], [3, 4]]
ruby-1.9.2-p290 :036 > a[0][0] = 100
=> 100
@cemeng
cemeng / gist:2927888
Created June 14, 2012 03:43
Rails Renaming Table
- Create migration + run it
- Rename model, controller
- Run specs
- Fix failing specs
@cemeng
cemeng / gist:2951838
Created June 19, 2012 01:40
Index FTW

I finally remember about index after running the rollback which was pretty fast - due to index on job_no.

Slowpoke

mysql> EXPLAIN SELECT * FROM comments, jobs WHERE target_type = 'Job' AND target_id = old_id;
+----+-------------+----------+------+---------------+------+---------+------+-------+------------------------------------------------+
| id | select_type | table    | type | possible_keys | key  | key_len | ref  | rows  | Extra                                          |
+----+-------------+----------+------+---------------+------+---------+------+-------+------------------------------------------------+
|  1 | SIMPLE      | jobs     | ALL  | NULL          | NULL | NULL    | NULL | 13498 |                                                |
@cemeng
cemeng / gist:2965288
Created June 21, 2012 11:46
Nested Attributes For
In the klass
class JobInvoice < SearchableRecord
.. yada yada yada ...
accepts_nested_attributes_for :job_invoice_items
end
In the view
@cemeng
cemeng / gist:2991909
Created June 25, 2012 22:41
Structuring CSS

Based on Octopress:

Alternative 1

Top Level

stylesheets/application.scss -> includes everything on base

@cemeng
cemeng / gist:3140712
Created July 19, 2012 04:16
Wicked PDF

Niggling issue on our scss file:

background-image: url("file://<%= Rails.application.assets.find_asset('company_logo_for_forms.png').pathname %>");

It'd be nice to implement a helper method on sass-rails to encapsulate that logic. Something like

Module Sass
@cemeng
cemeng / gist:3355490
Created August 15, 2012 03:38
Jasmine, Angular, Rails, Coffeescript - my oh my

Goals:

  • Support Coffeescript testing
  • Headless - run from command line
  • Test can be written in Coffeescript

Test libraries, two main alternatives:

  • Jasmine
  • Mocha

Jasmine is older - actively maintained by PivotalLabs, de facto JS testing for Rails projects? So I'd expect there are more gems/projects that integrate Jasmine and Rails compared to Mocha (at the moment anyway).