Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

jack-nie

🎯
Focusing
  • shenzhen
Block or report user

Report or block jack-nie

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jack-nie
jack-nie / movie-titles.rb
Created Jul 4, 2016 — forked from karmi/movie-titles.rb
Multiple analyzers and query fields in Elasticsearch for auto-completion
View movie-titles.rb
require 'tire'
# Tire.configure { logger STDERR, level: 'debug' }
Tire.index('movie-titles') do
delete
create \
settings: {
index: {
analysis: {
View gist:1d8c8ae8a2f5bd364f2fe1a82572d2e6
# 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
View 1_create_products.rb
Sequel.migration do
up do
run 'CREATE EXTENSION "uuid-ossp"'
create_table :products do
column :id, :uuid, :default => Sequel.function(:uuid_generate_v4), :primary_key => true
end
end
end
@jack-nie
jack-nie / stacked_middlewares.rake
Created Apr 9, 2016 — forked from tyabe/stacked_middlewares.rake
Display lists of all stacked rack middleware for your padrino app
View stacked_middlewares.rake
##
# This is rake task of padrino-framework
# Display lists of all stacked rack middleware for your padrino app.
# distributed under the MIT License(http://tyabe.mit-license.org/)
#
def stacked_middlewares(app, args)
require Padrino.root('config/boot.rb')
app_obj = app.app_obj
instance = app_obj.new!
build = app_obj.build(instance)
@jack-nie
jack-nie / array_to_proc.rb
Last active Sep 10, 2015 — forked from geowy/array_to_proc.rb
Array#to_proc, shorthand for creating a block that selects elements of an array/hash/collection.
View array_to_proc.rb
class Array
# Returns a proc which calls [] with the array's contents as arguments
#
# ====Usage
# [[1, 2], [3, 4], [5, 6]].map(&[0])
# # => [1, 3, 5]
#
# [{ hello: 'world' }, { hello: 'sun', goodbye: 'moon' }].map(&[:hello])
# # => ['world', 'sun']
@jack-nie
jack-nie / ova.rb
Last active Sep 10, 2015 — forked from 0x0dea/ova.rb
"Real" method overloading in Ruby!
View ova.rb
module Ova
# autovivifying map from [class][method][signature] to Method
@@Ova = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }
# Wrap #respond_to? for parity with Class#===.
Responder = Struct.new(:method) do
def === obj
obj.respond_to?(method)
end
end
You can’t perform that action at this time.