Skip to content

Instantly share code, notes, and snippets.

class Human
def initialize
end
def name=(name)
@name = name
end
def name
@name
@zsan
zsan / readme.md
Last active April 24, 2020 19:21
ruby design pattern - Template Method - Strategy

So our first job is to create a class to make a report

class Report
  def initialize
    @title = 'Monthly Report'
    @text = [ 'Things are going', 'really, really well.' ] 
  end
  def output_report
 puts('')
{
"city": {
"confidence": 25,
"geoname_id": 54321,
"names": {
"de": "Los Angeles",
"en": "Los Angeles",
"es": "Los Ángeles",
"fr": "Los Angeles",
"ja": "ロサンゼルス市",
<%= area_chart @campaigns.map { |campaign|
{
name: campaign.name,
data: campaign.jump.ahoy_events.joins(:visit).group_by_day(:started_at).count,
library: {
lineTension: 0.5,
borderWidth: 2,
# borderColor: "yellow",
borderCapStyle: "square",
borderJoinStyle: "bevel",
@zsan
zsan / 
Created February 24, 2016 17:07
city-big-leads.sql
mysql> select * from cities where number_of_leads > 1000;
+------+----------------------+-------+------------+-----------------+---------+
| id | name | state | population | number_of_leads | scraped |
+------+----------------------+-------+------------+-----------------+---------+
| 1 | New York | NY | NULL | 6995 | f |
| 2 | Los Angeles | CA | NULL | 2530 | f |
| 3 | Chicago | IL | NULL | 2939 | f |
| 4 | Houston | TX | NULL | 1613 | f |
| 5 | Phoenix | AZ | NULL | 1808 | f |
| 8 | Dallas | TX | NULL | 1944 | f |
@zsan
zsan / gum.sql
Last active August 29, 2015 14:15
#day 1
#table ads
+---------------+----------------+------------------------
| original price| latest price | url | edited
+---------------+----------------|---------------------
| 45000.00 | | http://www.g | 0
+---------------+----------------+-------------------------
#day 3, price changes
#table ads
for my $key(@$buss_names) {
my $org_name = $key->{organisationName}[0];
my $eff_date = $key->{effectiveFrom}[0];
# if matched
if ($eff_date eq $today or $eff_date eq $yesterday) {
# where should i put effective_date ($eff_date) ?
my $rs_final = $final_table->search(
{ abn => $abn, business_name => $org_name },
{ rows => 1 })->single;
{
"id"=>"TG410-2721:TG636-2817",
"comfort_index"=>0.0,
"fares"=>[{
"price"=>428.9,
"provider_code"=>"cheaptickets.sg",
"description"=>"Economy",
"alliance"=>"star_alliance",
"deeplink"=>"http://www.wego.com/flights/providers/2/deeplinks?search_id=avi_JI_9QsWwE1aFgprGJg&trip_id=SIN:TPE:2014-12-27&fare_id=cheaptickets.sg:22&route=SIN-TPE",
"deeplink_params"=>{
{
"id"=>"TZ202-2700",
"comfort_index"=>0.0,
"fares"=>[{
"price"=>133.64,
"provider_code"=>"sg.edreams.com",
"description"=>"Economy",
"alliance"=>"lcc",
"deeplink"=>"http://www.wego.com/flights/providers/2/deeplinks?search_id=avi_JI_9QsWwE1aFgprGJg&trip_id=SIN:TPE:2014-12-27&fare_id=sg.edreams.com:0&route=SIN-TPE",
"deeplink_params"=>
@zsan
zsan / user.rb
Created December 17, 2014 16:11
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :email
t.timestamps null: false
end
end
end