This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Doesn't check for existence of myApplication*/ | |
var myApplication = {}; | |
/* | |
Does check for existence. If already defined, we use that instance. | |
Option 1: if(!myApplication) myApplication = {}; | |
Option 2: var myApplication = myApplication || {}; | |
We can then populate our object literal to support models, views and collections (or any data, really): | |
*/ | |
var myApplication = { | |
models : {}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var galleryApp = galleryApp || {}; | |
// perform similar check for nested children | |
galleryApp.routers = galleryApp.routers || {}; | |
galleryApp.model = galleryApp.model || {}; | |
galleryApp.model.special = galleryApp.model.special || {}; | |
// routers | |
galleryApp.routers.Workspace = Backbone.Router.extend({}); | |
galleryApp.routers.PhotoSearch = Backbone.Router.extend({}); | |
// models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
ruby '2.0.0' | |
#ruby-gemset=railstutorial_rails_4_0 | |
gem 'rails', '4.0.0' | |
group :development do | |
gem 'sqlite3', '1.3.7' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To see what in the default register | |
:reg " | |
# To see what in the register 0 | |
:reg 0 # yank register |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem install pygements.rb | |
gem install redcarpet | |
npm -g install instant-markdown-d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [1, 2, 3, 4] | |
(0...arr.length - 1).map{|i| arr.dup.tap{ |a| a[i, 2] = a[i, 2].reverse } } | |
# => [[2, 1, 3, 4, 5], [1, 3, 2, 4, 5], [1, 2, 4, 3, 5], [1, 2, 3, 5, 4]] | |
a = [1, 2, 3] | |
# => [1, 2, 3] | |
(0...a.length - 1).map{|i| a.dup.tap{|a| a[i, 2] = a[i, 2].reverse}} | |
# => [[2, 1, 3], [1, 3, 2]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# read text from file, map to integer and sum all | |
File.new(file_name, 'r').each_line.map(&:strip).map(&:to_i).inject(:+) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'matrix' | |
arr = [ | |
%w(J O I J O), | |
%w(I J O J O), | |
%w(I I J I J) | |
] | |
myarr1 = Array(arr) | |
# [["J", "O", "I", "J", "O"], ["I", "J", "O", "J", "O"], ["I", "I", "J", "I", "J"]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://stackoverflow.com/questions/23382474/is-there-any-way-to-create-2-x-2-array-matrix-from-a-larger-array-matrix | |
require 'matrix' | |
def find_in_matrix(arr,sub) | |
sub_nrows = sub.size | |
sub_ncols = sub.first.size | |
rows = Array(0..(arr.size - sub_nrows)) | |
cols = Array(0..(arr.first.size - sub_ncols)) | |
arr_m = Matrix[*arr] | |
sub_m = Matrix[*sub] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[0, 0, 3], [0, 1, 4], [1, 0, 5], [1, 1, 6]].select{ |i, j, k| p "#{ i } is #{ j } is #{ k }" } | |
# "0 is 0 is 3" | |
# "0 is 1 is 4" | |
# "1 is 0 is 5" | |
# "1 is 1 is 6" | |
# => [[0, 0, 3], [0, 1, 4], [1, 0, 5], [1, 1, 6]] |
OlderNewer