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
" Highlight Ruby 1.8.x hash rocket
" This will prevent you to ever write it again
highlight ObsoleteHashRocket ctermbg=red guibg=red
au ColorScheme * highlight ObsoleteHashRocket guibg=red
au BufEnter * match ObsoleteHashRocket /=>/
au InsertEnter * match ObsoleteHashRocket /=>/
au InsertLeave * match ObsoleteHashRocket /=>/
@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 / 01_usage.rb
Created July 22, 2015 17:54
YAML Serializer with Syck Fallback
# Usage
class User
serialize :data, YAMLColumnWithSyckFallback.new
end
@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 / 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 / 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
@sikachu
sikachu / gist:4982127
Created February 19, 2013 00:54
calling object's method in method definition in Ruby
irb(main):001:0> class Foo
irb(main):002:1> def initialize(a, b = a.to_s)
irb(main):003:2> puts [a, b].inspect
irb(main):004:2> end
irb(main):005:1> end
=> nil
irb(main):006:0> Foo.new 1
[1, "1"]
=> #<Foo:0x007f973d9ca410>
@sikachu
sikachu / 01_function.zsh
Last active December 13, 2015 21:58
Open up the browser and create a new pull request
gpr() {
current_branch=`git rev-parse --abbrev-ref HEAD`
if [[ $1 != '' ]]; then
upstream=$1
else
upstream='master'
fi
origin_username=`git remote -v | grep 'origin.\+fetch' | sed "s/^.*github.com[\/:]\(.*\)\/\(.*\)\.git.*$/\1/"`
origin_repository=`git remote -v | grep 'origin.\+fetch' | sed "s/^.*github.com[\/:]\(.*\)\/\(.*\)\.git.*$/\2/"`
if [[ `git remote | grep sikachu` != '' ]]; then
Benchmark.bmbm do |x|
x.report('start_with?') { 10_000.times { "fooo".start_with?('foo') }}
x.report('regexp') { 10_000.times { "fooo" =~ /^foo/ }}
end