This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Api::ControllerHelpers | |
extend ActiveSupport::Concern | |
included do | |
include InstanceMethods | |
before_action :prepare_restful_params | |
end | |
module InstanceMethods | |
def prepare_restful_params |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveModel | |
class Serializer | |
# @api private | |
def relationship_value_for(association, adapter_options, adapter_instance) | |
return association.options[:virtual_value] if association.options[:virtual_value] | |
association_serializer = association.serializer | |
association_object = association_serializer && association_serializer.object | |
return unless association_object | |
# [Note] @Altech |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Api | |
## Used in ActionController | |
class Preloader | |
# @param [Array] attributes fields to select. | |
# @param [Hash] associations associations to include and fields to select of them. | |
# @example When you select id and name from companies, | |
# preload_for(companies, [:id, :name], {}) | |
# @example When you includes posts and employees and employees avatar, | |
# preload_for(companies, [], {posts: {}, employees: {avatar: {}}}) | |
def self.preload_for(rel, attributes, associations) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(kvs). | |
-export([start/0, store/2, lookup/1]). | |
start() -> register(kvs, spawn(fun() -> loop() end)). | |
store(Key, Value) -> rpc({store, Key, Value}). | |
lookup(Key) -> rpc({lookup, Key}). | |
rpc(Q) -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def modify_json(file_path) | |
require 'json' | |
require 'colorize' | |
require 'pry' | |
raise "The file is not exist!".red if not File.exists? file_path | |
json = JSON.parse(File.read(file_path)) | |
puts "json.keys: " + json.keys.join(",") | |
binding.pry |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gems | |
# ================================================== | |
# Segment.io as an analytics solution (https://github.com/segmentio/analytics-ruby) | |
gem "analytics-ruby" | |
# For encrypted password | |
gem "bcrypt-ruby" | |
# Useful SASS mixins (http://bourbon.io/) | |
gem "bourbon" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def squeeze(c) | |
s = "" | |
now = false | |
0.upto(self.size-1) do |i| | |
if self[i] == c | |
if now | |
next | |
else | |
s << self[i] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define-minor-mode modi-temporary-mode | |
"presentation mode of modi." | |
nil | |
" modi:temporary" | |
(list | |
(cons (kbd "C-;") 'modi:underline-region-temporary) | |
(cons (kbd "C-'") 'modi:bold-region-temporary) | |
(cons (kbd "C-.") 'modi:remove-decorations-of-region)) | |
(modi:visualize-decorations-of-buffer)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; **requirements** :: hoogle(cabal), ghc-mod(cabal,elisp) | |
(defun haskell-open-doc () | |
(interactive) | |
(let ((sym (thing-at-point 'symbol))) | |
(let* ((list-string (shell-command-to-string (concat "hoogle " sym))) | |
(list (haskell-open-doc-select-candidate (remove-if 'haskell-open-doc-filter (haskell-open-doc-parse list-string))))) | |
(if list | |
(let ((mod (nth 0 list)) (fun (nth 1 list)) (type (nth 2 list))) | |
(haskell-open-doc-uri-with-uri-fragment (concat (ghc-display-document-without-browse (ghc-resolve-package-name mod) mod nil) "#v:" fun))))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# used packs | |
queried_packs = ["暗黒時代", "陰謀", "基本", "繁栄"] | |
target_list = eval(DATA.read) | |
.select{|k,v| queried_packs.include? k} | |
.map{|k,v| v.map{|s| [k,s]}}.flatten(1) | |
set = Hash.new | |
10.times do |