Skip to content

Instantly share code, notes, and snippets.

View sikachu's full-sized avatar

Prem Sichanugrist sikachu

View GitHub Profile
@sikachu
sikachu / avoid_duplicate_ignored_columns.rb
Last active September 9, 2022 05:47
RuboCop cop to check and warn for duplicate call to `ActiveRecord::Base.ignore_columns=`
# frozen_string_literal: true
module RuboCop
module Cop
module Rails
# Checks for duplicate calls to ActiveRecord::Base.ignore_columns= as the
# subsequent calls will override the first call.
#
# @example
# # bad
@sikachu
sikachu / gist:f8d6b4767543cd2db9f4
Created January 26, 2016 16:04
rvm alias overrides
[~] rvm alias list
default => ruby-2.3.0
[~] rvm alias create 2.1 2.1.0
ruby-2.1.0 is not installed.
Creating alias 2.1 for ruby-2.1.0...
[~] rvm alias list
2.1 => ruby-2.1.0
default => ruby-2.3.0
[~] rvm alias create 2.1 2.1.8
ruby-2.1.8 is not installed.
@sikachu
sikachu / PS3.markdown
Created September 9, 2015 01:01
NA PSN 20 anniversary sale (Sep 8, 2015 - Sep 14, 2015)
@sikachu
sikachu / 01_usage.rb
Created July 22, 2015 17:54
YAML Serializer with Syck Fallback
# Usage
class User
serialize :data, YAMLColumnWithSyckFallback.new
end
@sikachu
sikachu / gist:bd57194442b01c9b143d
Last active July 9, 2017 18:26
Pretty print PlayStation Store listing
require "open-uri"
require "json"
API_URL = "https://store.playstation.com/chihiro-api/viewfinder/US/en/19/STORE-MSF77008-SUMMERSALEPSVGG?size=100&gkb=1&geoCountry=US"
STORE_URL = "https://store.playstation.com/#!/en-us/cid=%s"
data = JSON.parse(open(API_URL).read)
games = []
data["links"].each do |game|
@sikachu
sikachu / nowplaying-chrome.applescript
Last active February 19, 2016 21:41
Post current song playing in Google Play Music in Chrome to Colloquy
using terms from application "Colloquy"
on process user command c with arguments for view
try
if c is in {"nowplaying", "np", "playing"} then
tell application "Google Chrome"
repeat with w in (every window)
repeat with t in (every tab whose URL contains "play.google.com/music") of w
if (execute t javascript "document.getElementsByClassName('playing').length") is equal to 1 then
set tTitle to execute t javascript "document.getElementById('playerSongTitle').innerText;"
set tArtist to execute t javascript "document.getElementById('player-artist').innerText;"
@sikachu
sikachu / test.rb
Last active August 29, 2015 14:14
Fetch vs []
require "benchmark/ips"
hash = Hash.new
Benchmark.ips do |x|
x.report("fetch") { x = hash.fetch(:foo, "bar") }
x.report("fetch block") { x = hash.fetch(:foo) { "bar" } }
x.report("[]") { x = hash[:foo] || "bar" }
end
@sikachu
sikachu / quoting.applescript
Last active August 29, 2015 14:13
Green quoting for Colloquy
using terms from application "Colloquy"
on process outgoing chat message m
set messageBody to body of m as string
if messageBody starts with ">" then
set HTML of m to "<font color=\"green\">" & messageBody & "</font>"
end if
end process outgoing chat message
end using terms from

Keybase proof

I hereby claim:

  • I am sikachu on github.
  • I am sikachu (https://keybase.io/sikachu) on keybase.
  • I have a public key whose fingerprint is 7270 8199 79B1 6AD7 0571 6B7B 889C 472F 2DA2 8377

To claim this, I am signing this object:

@sikachu
sikachu / gist:7014735
Last active December 25, 2015 17:39
Get rid of libxml2 version mismatch when running Nokogiri
# Note: This assume that you're using libxml2 from Homebrew, which is keg-only.
# Run this command:
$ bundle config build.nokogiri --with-xml2-include=/usr/local/opt/libxml2/include/libxml2 --with-xml2-lib=/usr/local/opt/libxml2/lib --with-xslt-dir=/usr/local/opt
# Remove and rebundle. You use Bundler, right?
$ yes | gem uninstall nokogiri --force
$ bundle