Skip to content

Instantly share code, notes, and snippets.

@aquajach
aquajach / gist:d5ebe5dd833d6b27c0e0
Last active November 11, 2015 16:31
Best stock strategy quiz
prices = []
10.times do
prices << rand(1..100)
end
p "Today's prices are #{prices.join(', ')}"
min = max = prices.first
profit = 0
{
Field = "Table with Everything";
Rows = (
{
Fields = (
{
Uid = "522_73";
Values = (
);
},
@aquajach
aquajach / sti.rb
Last active October 8, 2015 10:02
Rails STI Pitfall (eager_load off)
class Person < ActiveRecord::Base
end
class Staff < Person
end
class Teacher < Staff
end
> Person.all.to_sql // "SELECT \"people\".* FROM \"people\""
@aquajach
aquajach / gist:d55a57931c2503d0cda0
Created June 2, 2015 06:57
Cube Crash Log in iPod Touch 5
Incident Identifier: 57DEF0EE-1D59-4D9F-B964-F50AEDAF84E8
CrashReporter Key: feb41b2edb9ca5ec937b84d25db077c80c5c2d24
Hardware Model: iPod5,1
Process: aggregated [28]
Path: /System/Library/PrivateFrameworks/AggregateDictionary.framework/Support/aggregated
Identifier: aggregated
Version: ???
Code Type: ARM (Native)
Parent Process: launchd [1]
@aquajach
aquajach / gist:64c1a772a99007284535
Created January 6, 2015 03:20
Exception in production
ActiveRecord::StatementInvalid (PG::SyntaxError: ERROR: syntax error at or near ")"
LINE 20: ...(CASE WHEN lower(partners_languages.language) IN () THEN 1 E...
^
:
SELECT users.id FROM (
SELECT users.id, (CASE WHEN lower(users.my_sector) = lower('Real Estate') THEN users.score + 2 ELSE users.score END) AS score
FROM (
SELECT users.id, users.my_sector, SUM(location) AS score
FROM (
SELECT
@aquajach
aquajach / gist:a0271fcf6551ad0a0e99
Last active August 29, 2015 14:12
Front-end style
#for css
body#search{
...
}
#for js
- if $('body#search').length
......
#for layout view file, e.g. applicaiton.html.haml
@aquajach
aquajach / gist:3529e5a7541620ad5e8f
Last active August 29, 2015 14:11
Is it possible?
<youtube-video data-code='hkk68&$'></youtube-video>
<template>
<iframe src="http://youtube.com/#{youtube-code}/"></iframe>
</template>
<!-- I want use the youtube-video element with code to get the iframe of of YouTube video --!>
<!-- Is it possible to make youtube-code in template generic as a variable whose value is data-code in youtube-video? --!>
<!-- The template is more complex than above in reality by the way --!>
@aquajach
aquajach / gist:8452229
Last active January 3, 2016 10:49
Rails validation message example
validates_presence_of :account, message: 'cant_be_blank'
#/config/locales/any_name_can_do.en.yml
en:
error_messages:
account:
cant_be_blank: "you have to fill in account field!"
class Calendar
def initialize(:view, :data, :callback)
end
end
@aquajach
aquajach / rails_array_hstore.rb
Last active December 27, 2015 13:09
[Monkey-Patch] Allow your rails4 to have a column as array of hash
module ActiveRecord
module ConnectionAdapters
class PostgreSQLAdapter < AbstractAdapter
module Quoting
def type_cast(value, column, array_member = false)
return super(value, column) unless column
case value
when Range
return super(value, column) unless /range$/ =~ column.sql_type