Skip to content

Instantly share code, notes, and snippets.

View bachue's full-sized avatar

Bachue Zhou bachue

View GitHub Profile
http://192.168.41.135:8080/solr/admin/cores?action=CREATE&name=collection2&instanceDir=/usr/local/collection2&config=/usr/local/collection2/conf/solrconfig.xml&schema=/usr/local/collection2/conf/schema.xml&dataDir=/usr/local/collection2/data
@bachue
bachue / test_assoc.rb
Created September 28, 2013 03:35
ActiveRecord 测试复杂的关系
class User < ActiveRecord::Base
has_and_belongs_to_many :followees, class_name: 'User', foreign_key: 'follower_id', association_foreign_key: 'follow_id', :join_table => 'follows'
has_and_belongs_to_many :followers, class_name: 'User', foreign_key: 'follow_id', association_foreign_key: 'follower_id', :join_table => 'follows'
has_many :followers_comments, through: :followers, :source => :comments
has_many :comments
end
@bachue
bachue / join_table_name.rb
Created September 29, 2013 06:07
原来ActiveRecord默认约定的join表名字是两个表哪个名字短哪个就排在前面啊 以前一直不知道的说
# Generates a join table name from two provided table names.
# The names in the join table names end up in lexicographic order.
#
# join_table_name("members", "clubs") # => "clubs_members"
# join_table_name("members", "special_clubs") # => "members_special_clubs"
def join_table_name(first_table_name, second_table_name)
if first_table_name < second_table_name
join_table = "#{first_table_name}_#{second_table_name}"
else
join_table = "#{second_table_name}_#{first_table_name}"
@bachue
bachue / datalist_test.html
Created October 9, 2013 05:34
an example about dynamic datalist, work for chrome & firefox
<!DOCTYPE html>
<html>
<head>
<title>Ruby on Rails: Welcome aboard</title>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(function() {
$('#input').on('input', function(e) {
var val = $(this).val();
if(val === "") return;
@bachue
bachue / strange_proc.rb
Created October 12, 2013 14:37
Why there's no `yield` in Proc.new but Proc.new can accept the block of the caller?
def f
Module.new &Proc.new
end
M = f do
def self.x
'hello world'
end
end
def f
puts 'f'
{}
end
def g
puts 'g'
1
end
@bachue
bachue / git.bachue.brewupdate.plist
Created April 16, 2014 14:20
For Mac OS X, run `brew update` every hour. Copy this file to ~/Library/LaunchAgents/git.bachue.brewupdate.plist to install.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>git.bachue.brewupdate</string>
<key>ProcessType</key>
<string>Background</string>
<key>EnvironmentVariables</key>
<dict>
@bachue
bachue / example.html
Created June 10, 2014 14:21
How to enable Autocomplete in the Ace editor
<html>
<body>
<div id="editor" style="height: 500px; width: 800px">Type in a word like "will" below and press ctrl+space or alt+space to get "rhyme completion"</div>
<div id="commandline" style="position: absolute; bottom: 10px; height: 20px; width: 800px;"></div>
</body>
<script src="https://rawgithub.com/ajaxorg/ace-builds/master/src/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="https://rawgithub.com/ajaxorg/ace-builds/master/src/ext-language_tools.js" type="text/javascript" charset="utf-8"></script>
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script>
var langTools = ace.require("ace/ext/language_tools");
@bachue
bachue / https_server.rb
Last active August 29, 2015 14:02
To create a basic HTTPSServer by Ruby
#!/usr/bin/ruby
require "socket"
require "openssl"
require "thread"
listeningPort = Integer(ARGV[0])
server = TCPServer.new(listeningPort)
sslContext = OpenSSL::SSL::SSLContext.new
@bachue
bachue / int8(float64).go
Last active August 29, 2015 14:04
Go could throw exception when type overflow, but not always.
package main
import (
"fmt"
"math"
)
func main() {
fmt.Printf("%d\n", int8(math.Pow(2, 10))) // => 0
}