Tuesday, 18 November 2014

rescue

(@lang = Language.find(@user_cookie[:language_id])) rescue @lang, value = find_default_lang_id
view raw gistfile1.rb hosted with ❤ by GitHub

Monday, 17 November 2014

the tbs google param

http://stenevang.wordpress.com/2013/02/22/google-search-url-request-parameters/
// http://jwebnet.net/advancedgooglesearch.html#advDatePeriod
// http://stackoverflow.com/questions/9452169/google-custom-search-refinement-for-newest-results
// &tbs=rltm:1 [real time results]
// &tbs=qdr:s [past second]
// &tbs=qdr:n [past minute]
// &tbs=qdr:h [past hour]
// &tbs=qdr:d [past 24 hours (day)]
// &tbs=qdr:w [past week]
// &tbs=qdr:m [past month]
// &tbs=qdr:y [past year]
// Any time: tbs=qdr:a
// Last second: tbs=qdr:s (Read more about this “real time search” on Lifehacker)
// Last minute: tbs=qdr:n
// Last 10 minutes: tbs=qdr:n10 (and so on for any number of minutes)
// Last hour: tbs=qdr:h
// Last 12 hours: tbs=qdr:h10 (and so on for any number of hours)
// Last day: tbs=qdr:d
// Last week: tbs=qdr:w
// Last month: tbs=qdr:m
// Last year: tbs=qdr:y
// A specific time range, for example from March 2 1984 to June 5 1987: tbs=cdr:1,cd_min:3/2/1984,cd_max:6/5/1987
// Sort by date: tbs=sbd:1
// Sort by relevance: tbs=sbd:0
view raw gistfile1.txt hosted with ❤ by GitHub

Saturday, 15 November 2014

rails 4 none filter

def filter(filter_name)
case filter_name
when :all
scoped
when :published
where(:published => true)
when :unpublished
where(:published => false)
else
none
end
end
view raw gistfile1.rb hosted with ❤ by GitHub

Thursday, 13 November 2014

unicode cldr REGIONS AND LANGUAGES

http://unicode.org/repos/cldr/trunk/common/main/
aa
aa_DJ
aa_ER
aa_ET
af
af_NA
af_ZA
agq
agq_CM
ak
ak_GH
am
am_ET
ar
ar_001
ar_AE
ar_BH
ar_DJ
ar_DZ
ar_EG
ar_EH
ar_ER
ar_IL
ar_IQ
ar_JO
ar_KM
ar_KW
ar_LB
ar_LY
ar_MA
ar_MR
ar_OM
ar_PS
ar_QA
ar_SA
ar_SD
ar_SO
ar_SS
ar_SY
ar_TD
ar_TN
ar_YE
as
as_IN
asa
asa_TZ
ast
ast_ES
az
az_Cyrl
az_Cyrl_AZ
az_Latn
az_Latn_AZ
bas
bas_CM
be
be_BY
bem
bem_ZM
bez
bez_TZ
bg
bg_BG
bm
bm_Latn
bm_Latn_ML
bn
bn_BD
bn_IN
bo
bo_CN
bo_IN
br
br_FR
brx
brx_IN
bs
bs_Cyrl
bs_Cyrl_BA
bs_Latn
bs_Latn_BA
ca
ca_AD
ca_ES
ca_ES_VALENCIA
ca_FR
ca_IT
cgg
cgg_UG
chr
chr_US
cs
cs_CZ
cy
cy_GB
da
da_DK
da_GL
dav
dav_KE
de
de_AT
de_BE
de_CH
de_DE
de_LI
de_LU
dje
dje_NE
dsb
dsb_DE
dua
dua_CM
dyo
dyo_SN
dz
dz_BT
ebu
ebu_KE
ee
ee_GH
ee_TG
el
el_CY
el_GR
en
en_001
en_150
en_AG
en_AI
en_AS
en_AU
en_BB
en_BE
en_BM
en_BS
en_BW
en_BZ
en_CA
en_CC
en_CK
en_CM
en_CX
en_DG
en_DM
en_ER
en_FJ
en_FK
en_FM
en_GB
en_GD
en_GG
en_GH
en_GI
en_GM
en_GU
en_GY
en_HK
en_IE
en_IM
en_IN
en_IO
en_JE
en_JM
en_KE
en_KI
en_KN
en_KY
en_LC
en_LR
en_LS
en_MG
en_MH
en_MO
en_MP
en_MS
en_MT
en_MU
en_MW
en_MY
en_NA
en_NF
en_NG
en_NR
en_NU
en_NZ
en_PG
en_PH
en_PK
en_PN
en_PR
en_PW
en_RW
en_SB
en_SC
en_SD
en_SG
en_SH
en_SL
en_SS
en_SX
en_SZ
en_TC
en_TK
en_TO
en_TT
en_TV
en_TZ
en_UG
en_UM
en_US
en_US_POSIX
en_VC
en_VG
en_VI
en_VU
en_WS
en_ZA
en_ZM
en_ZW
eo
eo_001
es
es_419
es_AR
es_BO
es_CL
es_CO
es_CR
es_CU
es_DO
es_EA
es_EC
es_ES
es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ss_SZ
ss_ZA
ssy
ssy_ER
sv
sv_AX
sv_FI
sv_SE
sw
sw_KE
sw_TZ
sw_UG
swc
swc_CD
ta
ta_IN
ta_LK
ta_MY
ta_SG
te
te_IN
teo
teo_KE
teo_UG
th
th_TH
ti
ti_ER
ti_ET
tn
tn_BW
tn_ZA
to
to_TO
tr
tr_CY
tr_TR
ts
ts_ZA
twq
twq_NE
tzm
tzm_Latn
tzm_Latn_MA
ug
ug_Arab
ug_Arab_CN
uk
uk_UA
ur
ur_IN
ur_PK
uz
uz_Arab
uz_Arab_AF
uz_Cyrl
uz_Cyrl_UZ
uz_Latn
uz_Latn_UZ
vai
vai_Latn
vai_Latn_LR
vai_Vaii
vai_Vaii_LR
ve
ve_ZA
vi
vi_VN
vo
vo_001
vun
vun_TZ
wae
wae_CH
xog
xog_UG
yav
yav_CM
yi
yi_001
yo
yo_BJ
yo_NG
zgh
zgh_MA
zh
zh_Hans
zh_Hans_CN
zh_Hans_HK
zh_Hans_MO
zh_Hans_SG
zh_Hant
zh_Hant_HK
zh_Hant_MO
zh_Hant_TW
zu
zu_ZA
view raw gistfile1.txt hosted with ❤ by GitHub

Wednesday, 12 November 2014

start end pagination

_start = @current_page >= 5 ? @current_page -5 : 1
_end = @current_page + 5
@pagination = Array(_start.._end)
view raw gistfile1.rb hosted with ❤ by GitHub

Tuesday, 11 November 2014

remove empty 00 from time

# video_time_to_human("00:05:20")
# => "05:20"
# video_time_to_human("10:05:20")
# => "10:05:20"
def video_time_to_human(time)
time = time.split(":")
time.delete_at(0) if time.first == "00"
time.join(":")
end
view raw gistfile1.rb hosted with ❤ by GitHub

rails enable i18n fallbacks

#in application.rb
#enable fallbacks
config.i18n.fallbacks =[:en]
view raw gistfile1.rb hosted with ❤ by GitHub

Friday, 7 November 2014

IBeacon

https://github.com/AltBeacon/android-beacon-library

http://www.easibeacon.com/doc/
https://github.com/msroot/motion-beacon-example
http://blog.willrax.com/ibeacons-and-rubymotion/
http://buyibeacons.com/

http://estimote.com/
https://github.com/chrishale/proximity-motion
https://teamstrobe.com/2014/02/07/ibeacons-with-rubymotion.html
http://blog.willrax.com/ibeacons-and-rubymotion/
http://en.wikipedia.org/wiki/IBeacon

Monday, 3 November 2014

access helpers from controllers

def update_stats
render json: {
new_users: view_context.number_helper(User.created_today.count),
new_searches: view_context.number_helper(Query.searches_today)
}
end
view raw gistfile1.rb hosted with ❤ by GitHub

rails number_helper

module ApplicationHelper
# make number 123123123 1K
def number_helper(number)
number_to_human(number, :format => '%n%u', :units => { :thousand => 'K' })
end
end
view raw gistfile1.rb hosted with ❤ by GitHub

Sunday, 2 November 2014

unicorn on heroku

In  config/unicorn.rb


 
config/unicorn.rb
# With a typical Rails memory footprint, you can expect to run 2-4 Unicorn worker processes.
# https://devcenter.heroku.com/articles/rails-unicorn
# config/unicorn.rb
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 1)
timeout 15
preload_app true
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
view raw gistfile1.rb hosted with ❤ by GitHub
Procfile

 
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
view raw gistfile1.txt hosted with ❤ by GitHub
Gemfile






 
source 'https://rubygems.org'
ruby '2.1.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.6'
gem 'unicorn'
group :production do
gem "rails_12factor"
end
gem "pg"
group :development, :test do
# gem "sqlite3", :require => "sqlite3"
gem "better_errors"
gem "binding_of_caller"
end
gem "faker"
gem "devise"
gem 'simple_form'
gem 'annotate'
gem 'bootstrap-generators', '~> 3.0.2'
gem 'high_voltage'
gem 'will_paginate', '~> 3.0'
gem 'will_paginate-bootstrap'
gem 'groupdate'
gem 'chartkick'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
# gem 'jquery-rails'
# Use sqlite3 as the database for Active Record
# gem 'sqlite3'
# Use SCSS for stylesheets
# gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
# gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
# gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
# gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
# gem 'sdoc', '~> 0.4.0', group: :doc
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
view raw gistfile1.txt hosted with ❤ by GitHub
or start on localhost bundle exec unicorn -p 3000