Skip to content

Instantly share code, notes, and snippets.

View goodfeel's full-sized avatar
:octocat:

Jesdakorn Samittiauttakorn goodfeel

:octocat:
View GitHub Profile
@goodfeel
goodfeel / gist:7577308
Created November 21, 2013 07:21
Find process using port number on Mac OS X
sudo lsof -i :<port number>
# e.g. sudo lsof -i :8080
@goodfeel
goodfeel / ga.rb
Last active August 16, 2017 04:06
Ruby class for Download Aggregrated Data from GameAnalytics.com
# Communicate with GameAnalytics.com to download aggragrated data.
# Author: Jesdakorn S. (@thet0ny / http://www.ton.in.th / http://zaqqle.com)
require 'rubygems'
require 'active_support/core_ext/date'
require 'active_support/core_ext/numeric/time' # Date time helper (when use outside Rails)
require 'HTTParty' # gem install httparty
require 'JWT' # gem install jwt
@goodfeel
goodfeel / hstore_query.rb
Created August 20, 2014 08:10
My custom HstoreQuery, this is a hacking solution with typecast on hStore value for comparison. My model already infers the data type.
class HstoreQuery
attr_accessor :klass, :hstore_field, :parent
# parent = Game.first.players
# a = HstoreQuery.new Player, 'game_values', parent
# a.search 'float_money', '>', 9
def initialize(klass, field, parent = nil)
self.klass = klass
self.hstore_field = field
@goodfeel
goodfeel / ransack.rb
Last active August 29, 2015 14:06
Ransack Note
# hstore customized, in the model.
# given your h store field is 'data' and the hash key named 'trace'
ransacker :trace do |parent|
Arel::Nodes::InfixOperation.new('->', parent.table[:data], 'trace')
end
# Filter some field out when query field selection for ransack from (Still put in your model)
def self.ransackable_attributes(auth_object = nil)
super - ['id', 'player', 'updated_at']
end
@goodfeel
goodfeel / go.conf
Created September 22, 2014 02:01
Start Gin as a process at startup using upstart on Ubuntu
start on started network
stop on stopping network
kill signal INT
respawn
script
export GOROOT=/home/ton/go
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$GOROOT/bin
export GOPATH=$GOROOT/gocode
@goodfeel
goodfeel / forcessl.rb
Created November 18, 2014 01:31
Capybara + Poltergeist failed to visit a path in force SSL environment
Capybara.register_driver :poltergeist_ssl do |app|
Capybara::Poltergeist::Driver.new(app, js_errors: false, timeout: 5000, phantomjs_options: ['--ignore-ssl-errors=yes', '--ssl-protocol=any'])
end
Capybara.default_driver = :poltergeist_ssl
@goodfeel
goodfeel / ffmpeg
Last active September 11, 2015 01:16
Install ffmpeg on Amazon AMI
As Amazon AMI is a subset of Redhat so most of the tutorials will turn you to `yum` by adding or configuring some repo config file which those repo is old and tutorials are no longer valid.
To make it super easy, I would recommend you to use a static build of `ffmpeg` which you can find it at:
http://johnvansickle.com/ffmpeg/
Get a latest stable release version (the 3rd or 4th line e.g. 2.5 at the moment of writing) not the 1st - 2nd line which is considerable as a unreleased build and maybe unstable. You can go ahead and copy a download link which correct to your machine CPU architecture e.g. 64bits
After that `ssh` to your Amazon EC2 and do:
```
@goodfeel
goodfeel / logrotate
Created April 6, 2015 02:15
Logrotate - Chef Rails
cd /var/log
sudo mkdir rails
sudo chown ec2-user:ec2-user rails
# /etc/logroate.conf
# Rotate weekly and when reached 52 rotations, notify or remove
# compress to .gz with delaycompress (compress will be done on next round of logrotation)
# ignore size 0 file
# copytruncate so we don't need to restart unicorn.
@goodfeel
goodfeel / swap
Last active September 16, 2015 01:28
Amazon AMI Swapfile Setup
sudo /bin/dd if=/dev/zero of=/var/swap1 bs=1G count=3 #(block size 1G for 3 which is 3GB in total)
# or sudo /bin/dd if=/dev/zero of=/var/swap1 bs=1M count=2048
sudo /sbin/mkswap /var/swap1
# Change permission so the swap file is secured.
sudo chmod 0600 /var/swap1
# Turn swap on
sudo /sbin/swapon /var/swap1
# Add auto (mount/)swapon when instance start
sudo vi /etc/fstab
@goodfeel
goodfeel / mysql_dump
Created May 21, 2015 01:20
mysqldump with query
mysqldump DATABASE --tables logs --where="created_at < '2015-03-01'" -u XXXX -pXXXXX --host ZZZZZZ.com > data.sql