Skip to content

Instantly share code, notes, and snippets.

View vanakenm's full-sized avatar

Martin Van Aken vanakenm

View GitHub Profile
@vanakenm
vanakenm / ArrayEqualTest
Created February 21, 2013 15:33
Can someone explain to me how the "-" method work on array ?
require 'minitest/autorun'
require 'minitest/spec'
class ElementTest
attr_accessor :value
def ==(other)
value == other.value
end
<% content_for :header do %>
<%= javascript_include_tag "filters" %>
<% end %>
<h1>Show posts</h1>
<header>
<section id="statistics">
<p>Currently <%= @posts.size %> in <%= @posts.map(&:category).uniq.size %> different categories.</p>
<p>Most recent category: <%= @posts.first.category %>
</section>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Blog</title>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
@vanakenm
vanakenm / gist:11839af65f0111d7cc8b
Created January 13, 2015 16:48
Days since Christmas
require 'date'
def xmas_count
if Time.now.month == 12 && Time.now.day >= 25
(Date.today - Date.new(Time.now.year, 12, 25)).to_i
else
(Date.today - Date.new(Time.now.year-1, 12, 25)).to_i
end
end
@vanakenm
vanakenm / case.rb
Created January 14, 2015 10:23
A case in uby
a = 5
case a
when 1..3
puts "Is smaller or equal to three"
when 4..6
puts "Is smaller or equal to six"
else
puts "Is BIG"
end
@vanakenm
vanakenm / gist:2433a0fabf7846c55558
Created January 16, 2015 17:15
Printing the students
students = [{name: "Laura", age: 10, enlisted: true},
{name: "Bob", age: 22},
{name: "Stephan", age: 18},
{name: "Lisa", age: 27, enlisted: true}]
def the_list(students)
students.map do |student|
enlisted = "* " if student[:enlisted]
"#{enlisted}#{student[:name]} #{student[:age]}"
end
@vanakenm
vanakenm / gist:d0f6cc4f8bb03f4fb224
Created February 2, 2015 10:32
One sentence pitch from Adeo Ressi (founder institute)
My company, _(insert name of company)_,
is developing _(a defined offering)_
to help _(a defined audience)_
_(solve a problem)_
with _(secret sauce)_
@vanakenm
vanakenm / gist:e45578bcd70f2ecd133a
Created February 19, 2015 11:16
Deploying to Heroku - Co.Station version
Follow the lecture for the Heroku signup & install. Use the Heroku create & push (git push heroku master).
The next step is supposed to be: heroku run rake db:migrate (we want to migrate our DB on the production server).
This will not work on Co.Station Member network (the one we are using for the internet connection), due to port 5000 being blocked (whole story: https://devcenter.heroku.com/articles/one-off-dynos#troubleshooting)
Workaround: get to another connection. Anyone with a data plan can access Internet using his/her smartphone, and you can then create a small "HotSpot" (a wifi network) out of it. Switch your laptop to that network, run that rake command (which should work), and switch back (to avoid data costs but mostly because the connection is much faster).
class Patient
attr_reader :name, :cured, :id
attr_accessor :room
def initialize(attributes)
@name = attributes[:name]
@id = attributes[:id].to_i
@cured = attributes[:cured] || false
# Before using, download the database [from the lecture](http://karr.lewagon.org/assets/02_sql_crud_doctors-cf43cfaf07025130e638de583d55e0ec.db)
# and save it as "doctors.db" in the same folder as this file
require 'sqlite3'
DB = SQLite3::Database.new("doctors.db")
class Doctor
attr_reader :id
attr_accessor :name, :age, :specialty