Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Xuncheng Wang xuncheng

🏠
Working from home
Block or report user

Report or block xuncheng

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
@xuncheng
xuncheng / dash2.rb
Created Jun 19, 2017
A cask for Dash 2.x
View dash2.rb
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
View model.template.txt
class Klass < ActiveRecord::Base
#
# Attributes
#
#
# Constants & Enums
#
@xuncheng
xuncheng / elasticsearch_cleaner.rb
Last active Jan 23, 2017
fix `Elasticsearch::Transport::Transport::Errors::ServiceUnavailable: [503]`
View elasticsearch_cleaner.rb
# 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')
View rspec_model_testing_template.rb
# 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:
View gist:a569d9953b88f4fcf06a
[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
View include_vs_extend_in_ruby.rb
module Foo
def bar
puts 'foobar'
end
end
class IncludeModule
include Foo
end
@xuncheng
xuncheng / gist:2354ea8656fac88d1f01
Last active Sep 10, 2015
generate a uuid in javascript
View gist:2354ea8656fac88d1f01
// 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);
});
}
View ruby_match_js_date.rb
# => 2007-11-19T08:37:48-06:00 Safari下只能Parse这种格式的时间
Time.now.strftime("%FT%T%:z")
View unsure.rb
$sure = false
t = Thread.new {
begin
# nada
ensure
sleep
$sure = true
# cleanup all the things
end
View has_many_documents.rb
# 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
You can’t perform that action at this time.