Skip to content

Instantly share code, notes, and snippets.

@jcsky
jcsky / index.html
Created March 2, 2016 15:47
Qunit TDD practice
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>TDD Practice</title>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.20.0.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
@jcsky
jcsky / admin-product.rb
Created April 5, 2016 03:21 — forked from ottodranik/admin-product.rb
Example: Use Acts-As-Taggable-On gem with Active-Admin and rails observers
ActiveAdmin.register Product do
permit_params :name, :category_id, :description, :text, :slug, :in_slider, :tag_ids => []
filter :category
filter :base_tags
filter :name
filter :text
filter :created_at
filter :updated_at
@jcsky
jcsky / db_pull.rake
Created May 26, 2016 02:43
dump staging/production db and restore to local db, just use rake:db_pull
namespace :db do
desc 'Pull staging db to development'
task :pull => [:dump, :restore]
task :dump do
dumpfile = "#{Rails.root}/tmp/latest.dump"
puts 'PG_DUMP on staging database...'
staging = Rails.application.config.database_configuration['staging']
system "ssh user@server 'PGPASSWORD=\"#{staging['password']}\" pg_dump -U postgres #{staging['database']} -h #{staging['host']} -F t' > #{dumpfile}"
puts 'Done!'
module Dojo
A = "Dojo - A"
B = "Dojo - B"
class Dojo_child
def print_a
p "Dojo_child print_a - A: #{A}"
end
end
module Kata
library(reshape2)
library(dplyr)
library(vegan)
library(ggplot2)
library(ggdendro)
Taipower <- read.csv(("https://johnsonhsieh.github.io/DSC2016-R/data/Taipower_top100.csv"),fileEncoding = "big5")
aop = Taipower$attr_of_procurement
T = mutate(Taipower, category = substr(aop,1,5), category_detail = unlist(lapply(strsplit(as.character(aop), split = ">"),"[",2)))
@jcsky
jcsky / gist:60cbac8ddb36b9d65a0b2fc7fa0c3bde
Created July 25, 2016 01:36
set_i18n_locale_from_browser
class ApplicationController < ActionController::Base
before_action :set_locale
private
def set_locale
if current_user
if !current_user.locale.present?
set_i18n_locale_from_browser
current_user.update(locale: I18n.locale.to_s)
@jcsky
jcsky / cookie_locale.txt
Last active July 25, 2016 01:48
set and get locale through cookie
class SystemLogger
def initialize
@sys_logs = []
end
def add(msg)
timestamp = Time.now.strftime('%Y%m%d_%H%M%S_%N')
@sys_logs << [timestamp, msg]
end
# 原本的,會出現origin is not allowed by Access-Control-Allow-Origin 的錯誤
config.middleware.insert_before 0, Rack::Cors do
allow do
origins /amazingtalker.com\z/
resource '*',
headers: ['AtToken', 'AtLocale'],
methods: [:get, :post, :delete, :put, :patch, :options],
credentials: true
end
end
@jcsky
jcsky / sample.rb
Created March 8, 2018 02:14
how to refactor nested private method?
class A
def hi
action_1
action_2
action_3
end
private
def action_1