Skip to content

Instantly share code, notes, and snippets.

View run26kimo's full-sized avatar
👋
Hello ~

RichKe run26kimo

👋
Hello ~
  • Taipei, Taiwan
View GitHub Profile
@run26kimo
run26kimo / rspec_model_testing_template.rb
Created June 19, 2017 04:24 — forked from SabretWoW/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@run26kimo
run26kimo / index.html
Created November 14, 2016 06:44 — forked from anonymous/index.html
Capture FB Reactions count and show them on webpage
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My FB Reactions Page</title>
<style>
html {
box-sizing: border-box;
width: 100%;
@run26kimo
run26kimo / rgb_to_lab.js
Created September 6, 2016 16:37 — forked from kfitfk/rgb_to_lab.js
Convert RGB color to CIE LAB color
function rgbToXyz(r, g, b) {
r /= 255
g /= 255
b /= 255
if (r > 0.04045) r = Math.pow(((r + 0.055) / 1.055), 2.4)
else r = r / 12.92
if (g > 0.04045) g = Math.pow(((g + 0.055) / 1.055), 2.4)
else g = g / 12.92
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Returns the result of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111
@run26kimo
run26kimo / Gemfile
Last active March 15, 2016 03:07 — forked from zealot128/crawler.rb
Web Crawler Helper class based upon Poltergeist (PhantomJS).Using Capybara as framework for building webcrawlers is surprisingly convenient
gem 'capybara'
gem 'poltergeist'
# in controller
# for local files
send_file '/path/to/file', :type => 'image/jpeg', :disposition => 'attachment'
# for remote files
require 'open-uri'
url = 'http://someserver.com/path/../filename.jpg'
data = open(url).read
send_data data, :disposition => 'attachment', :filename=>"photo.jpg"
# Optimized for writes, sort on read
# LVC
redis.hset("bonds|1", "bid_price", 96.01)
redis.hset("bonds|1", "ask_price", 97.53)
redis.hset("bonds|2", "bid_price", 95.50)
redis.hset("bonds|2", "ask_price", 98.25)
redis.sadd("bond_ids", 1)
redis.sadd("bond_ids", 2)
@run26kimo
run26kimo / controller.rb
Created August 27, 2012 06:06 — forked from joakimk/controller.rb
A way to lazy load partials in Rails 3
class Controller
include LazyLoad
def show
@model = Model.find(...)
respond_to do |format|
format.html do
@html_specific_data = Model.find(...)
end