Skip to content

Instantly share code, notes, and snippets.

View xuncheng's full-sized avatar
🎯
Focusing

Xuncheng Wang xuncheng

🎯
Focusing
View GitHub Profile
@xuncheng
xuncheng / dash2.rb
Created June 19, 2017 14:31
A cask for Dash 2.x
cask 'dash2' do
version '2.2.6'
sha256 'a7de5e00528611f86d1024164b1b5d536ce039344b6ca3c211918c7458f7e412'
url "https://kapeli.com/downloads/v#{version.major}/Dash.zip"
name 'Dash'
homepage 'https://kapeli.com/dash'
auto_updates true
@xuncheng
xuncheng / model.template.txt
Last active March 1, 2017 07:55 — forked from joshuapinter/model.template.txt
Rails Model Template
class Klass < ActiveRecord::Base
#
# Attributes
#
#
# Constants & Enums
#
@xuncheng
xuncheng / elasticsearch_cleaner.rb
Last active January 23, 2017 06:15
fix `Elasticsearch::Transport::Transport::Errors::ServiceUnavailable: [503]`
# fixed: Elasticsearch::Transport::Transport::Errors::ServiceUnavailable: [503]
# https://hugotunius.se/2015/06/22/elasticsearch-falkiness-in-tests.html
# https://medium.com/@thetron/dealing-with-503-errors-when-testing-elasticsearch-integration-in-rails-ec7a5f828274#.ex6quza03
# https://github.com/elastic/elasticsearch-ruby/issues/181#issuecomment-112781924
# spec/support/elasticsearch_cleaner.rb
RSpec.configure do |config|
config.before(:each, :es => true) do
ElasticsearchModel.create_index!(:force => true)
ElasticsearchModel.client.cluster.health(wait_for_status: 'yellow')
# 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:
[General]
loglevel = notify
[Proxy]
Proxy = custom, 1.2.3.4, 443, rc4-md5, password, http://surge.run/SSEncrypt.module
[Rule]
DOMAIN-KEYWORD,google,Proxy,force-remote-dns
DOMAIN-KEYWORD,facebook,Proxy,force-remote-dns
DOMAIN-KEYWORD,youtube,Proxy,force-remote-dns
module Foo
def bar
puts 'foobar'
end
end
class IncludeModule
include Foo
end
@xuncheng
xuncheng / gist:2354ea8656fac88d1f01
Last active September 10, 2015 07:58
generate a uuid in javascript
// JavaScript Version
uuid = function(e) {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = (c == 'x' ? r : (r & 0x3 | 0x8));
return v.toString(16);
});
}
# => 2007-11-19T08:37:48-06:00 Safari下只能Parse这种格式的时间
Time.now.strftime("%FT%T%:z")
@xuncheng
xuncheng / unsure.rb
Last active September 9, 2015 16:13 — forked from raggi/unsure.rb
$sure = false
t = Thread.new {
begin
# nada
ensure
sleep
$sure = true
# cleanup all the things
end
# source: http://hashrocket.com/blog/posts/bridging-activerecord-and-mongoid
module Extensions::ActiveRecord::HasManyDocuments
extend ActiveSupport::Concern
module ClassMethods
def has_many_documents(association_name, options = {})
class_eval %<
def #{association_name}
#{association_name.to_s.singularize.classify}.where(#{name.underscore}_id: id)
end