This file contains hidden or 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
Despite being a rubyist for years, I was fooled by this | |
irb> a = b = c = [] | |
irb> a << 1 | |
=> [1] | |
irb> b | |
=> [1] | |
irb> c | |
=> [1] |
This file contains hidden or 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
2.0.0-p247 :002 > t = Tweet.new | |
=> #<Tweet id: nil, content: nil> | |
2.0.0-p247 :003 > t.content = "Tweet without time" | |
=> "Tweet without time" | |
2.0.0-p247 :004 > t.save | |
(0.3ms) begin transaction | |
SQL (0.9ms) INSERT INTO "tweets" ("content") VALUES (?) [["content", "Tweet without time"]] | |
(190.3ms) commit transaction | |
=> true | |
2.0.0-p247 :005 > Tweet.all |
This file contains hidden or 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
class CreateTweets < ActiveRecord::Migration | |
def change | |
create_table :tweets do |t| | |
t.text :content | |
end | |
end | |
end |
This file contains hidden or 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
module Searchable | |
extend ActiveSupport::Concern | |
included do | |
## | |
# A simple search method | |
def self.search text | |
columns = self::SearchableColumns | |
words = text.downcase.gsub(/[^a-z0-9\s]/i, ' ').split(/\s+/) | |
query_array_2 = [] |
This file contains hidden or 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
console.log("Hello World!\n"); | |
function sort_by_price(a, b){ | |
return a.price > b.price; | |
} | |
array = [{price: 100}, {price: 50}, {price: 70}]; | |
console.log(array); | |
sorted_array = array.sort(sort_by_price); |
This file contains hidden or 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
class Fixnum | |
def prime? | |
return true if self == 1 | |
2.upto(self) do |num| | |
if self % num == 0 | |
return self == num | |
end | |
end | |
end | |
end |
This file contains hidden or 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 prime(num): | |
if num == 1: | |
return True | |
for i in range(num): | |
if (num % (i + 2)) == 0: | |
if num == (i + 2): | |
return True | |
else: | |
return False |
This file contains hidden or 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
class Fixnum | |
def prime? | |
return true if self == 1 | |
2.upto(self) do |num| | |
if self % num == 0 | |
return self == num | |
1.upto(100) do |num| | |
puts num if num.prime? |
This file contains hidden or 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
$ pip install pyftpdlib | |
$ python -m pyftpdlib | |
# Temporary FTP server |
This file contains hidden or 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
class User < ActiveRecord::Base | |
def status time = Time.now | |
statuses.where("created_at <= '#{time.to_s(:db)}'"). | |
order("created_at desc").first | |
end | |
end |