Skip to content

Instantly share code, notes, and snippets.

@radcliff
radcliff / transform_pg_array.rb
Last active August 29, 2015 14:19
Transforming PostgreSQL arrays
# monkey patch String class
# source: http://drawingablank.me/blog/ruby-boolean-typecasting.html
class String
def to_bool
return true if self == true || self =~ (/^(true|t|yes|y|1)$/i)
return false if self == false || self.empty? || self =~ (/^(false|f|no|n|0)$/i)
raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
end
end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@radcliff
radcliff / multiplication-table-test.rb
Last active August 29, 2015 14:25
Print out a multiplication table
require 'multiplication-table'
require 'minitest/autorun'
class TestPrinter < MiniTest::Unit::TestCase
def test_for_create_table
table = create_mult_table(3)
assert_equal(3, table.size)
assert_equal(3, table[0].size)
assert_equal(9, table[2][2])
@radcliff
radcliff / spreadsheet-test.rb
Last active August 29, 2015 14:25
Design a spreadsheet engine in Ruby
require 'spreadsheet'
require 'minitest/autorun'
class TestSpreadsheet < MiniTest::Test
def setup
@sheet = Spreadsheet.new([2,2], "Sheet")
end
def test_for_iniatialize
assert_equal(2, @sheet.rows)
@radcliff
radcliff / kinds.json
Last active August 29, 2015 14:25
Lemons - Items kinds (types)
{
"kinds": [
{
"option": "Lemons",
"value": "lemons"
},
{
"option": "Tomatoes",
"value": "tomatoes"
},
English short name lower case Alpha-2 code Alpha-3 code Numeric code ISO 3166-2
Afghanistan AF AFG 004 ISO 3166-2:AF
Åland Islands AX ALA 248 ISO 3166-2:AX
Albania AL ALB 008 ISO 3166-2:AL
Algeria DZ DZA 012 ISO 3166-2:DZ
American Samoa AS ASM 016 ISO 3166-2:AS
Andorra AD AND 020 ISO 3166-2:AD
Angola AO AGO 024 ISO 3166-2:AO
Anguilla AI AIA 660 ISO 3166-2:AI
Antarctica AQ ATA 010 ISO 3166-2:AQ
@radcliff
radcliff / 0_reuse_code.js
Last active September 17, 2015 21:51
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@radcliff
radcliff / array.js
Created November 8, 2015 17:46 — forked from NuckChorris/array.js
In Ember-CLI, transforms are located in app/transforms/name.js
// app/transforms/array.js
import Ember from 'ember';
import DS from 'ember-data';
export default DS.Transform.extend({
deserialize: function(value) {
if (Ember.isArray(value)) {
return Ember.A(value);
} else {
return Ember.A();
@radcliff
radcliff / 2to3LetterCountryData
Created January 13, 2016 14:51 — forked from 5herah/2to3LetterCountryData
Countries! ISO Alpha-2 Codes with their ISO Alpha-3 Code counterparts
{
"AF":"AFG",
"AX":"ALA",
"AL":"ALB",
"DZ":"DZA",
"AS":"ASM",
"AD":"AND",
"AO":"AGO",
"AI":"AIA",
"AQ":"ATA",
@radcliff
radcliff / README.md
Created January 13, 2016 14:53 — forked from mcallaghan/README.md
Country Codes

#Country Codes This uses the CIA World Factbook compendium of country codes to convert one type of code to another easily and programmatically. The table on this website was converted into JSON format on 20/11/2014.

As an example, enter the input code type, a code, and the output code type (separated by commas) above. Choose between the following options (Case sensitive)

- name
- GEC
- ISO_ALPHA_2
- ISO_ALPHA_3