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
# Old way | |
hash = { | |
"starts_at" => Date.today.to_s, | |
"ends_at" => (Date.today + 2.days).to_s | |
} | |
# Alternative way | |
hash = { | |
"starts_at" => Date.today, | |
"ends_at" => Date.today + 2.days | |
} |
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
cd .git/info/exclude | |
# add the file I want to exclude. |
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
Spree::Product.all.each do |product| | |
if product.id%2 == 0 | |
product.send(:update_attributes!, name: "casual female style") | |
product.send(:update_attributes!, meta_description: "https://dl.dropbox.com/s/pufh630xex4t12b/original_female.jpg", meta_keywords: "https://dl.dropbox.com/s/oj2tw4mqyev4jab/female_styled.jpeg") | |
else | |
product.send(:update_attributes!, name: "casual male style") | |
product.send(:update_attributes!, meta_description: "https://dl.dropbox.com/s/6639119teyh533i/original_male.jpeg", meta_keywords: "https://dl.dropbox.com/s/376mmsprv8w1oib/male_style.jpeg") | |
end | |
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
Spree::Product.all.each do |p| | |
p.update_attributes!(price: p.price+100) | |
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
dataset = [] | |
w = 500 | |
h = 400 | |
padding = 30 | |
dataset.push [ Math.random() * w, Math.random() * h ] for [0..50] | |
svg = d3.select("body") | |
.append("svg") | |
.attr("width", w) |
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
# assume that we have Leiningen installed | |
mkdir project_name | |
mkdir project_name/src | |
# create project.clj | |
(defproject incanter-helloworld "0.1.0" | |
:description "The Incanter version of hello world." | |
:dependencies [[incanter "1.2.3-SNAPSHOT"]] | |
:main hello) | |
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
(use 'incanter.core) | |
;; basic arithmetic | |
($= 7 + 8 - 2 * 6 / 2) ; => 9 | |
;; add 5 to each element of the vector [1 2 3] | |
($= [1 2 3] + 5) ; => (6 7 8) |
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 'csv' | |
module Exporter | |
DEFAULT_EXPORT_TABLES = [ Invoice, InvoiceItem, Item, Merchant, Transaction, User ] | |
DESTINATION_FOLDER = "tmp/" | |
def self.included(klass) | |
klass.extend ClassLevelMethods | |
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
def change | |
create_table :users do |t| | |
t.references :account #account_id | |
t.references :profile #profile_id | |
#... | |
end | |
add_index :accounts, [:account_id, :token], :unique => true, :name => 'by_account_token' | |
add_index :accounts, :profile_id, :unique => true, :name => 'by_profile' | |
add_index :accounts, [:account_id, :display_name], :name => 'by_account_profile' |
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
1.9.3p125 :018 > ""[0..1] | |
=> "" | |
1.9.3p125 :019 > ""[0] | |
=> nil |
OlderNewer