Skip to content

Instantly share code, notes, and snippets.

View liuzxc's full-sized avatar
🎯
Focusing

刘兴起 liuzxc

🎯
Focusing
View GitHub Profile
@liuzxc
liuzxc / gist:b82550d9001c4a7c11f4a8e194161c3f
Last active November 8, 2019 15:54
git diff mongoid field change
git diff develop --unified=0 -G "\+?field :" |grep "field" | awk '{print $1,$3,$5}'
+ :wechat_country, String
- :distinct_id, String
git diff develop --unified=0 -G "\+?field :" |grep "class" | awk '{print $6}'
User
@liuzxc
liuzxc / regex.md
Created November 8, 2019 15:45 — forked from vitorbritto/regex.md
Regex Cheat Sheet

Regular Expressions

Basic Syntax

  • /.../: Start and end regex delimiters
  • |: Alternation
  • (): Grouping
@liuzxc
liuzxc / bijective.rb
Created September 29, 2018 03:52 — forked from zumbojo/bijective.rb
Simple bijective function (base(n) encode/decode)
# Simple bijective function
# Basically encodes any integer into a base(n) string,
# where n is ALPHABET.length.
# Based on pseudocode from http://stackoverflow.com/questions/742013/how-to-code-a-url-shortener/742047#742047
ALPHABET =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split(//)
# make your own alphabet using:
# (('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a).shuffle.join
@liuzxc
liuzxc / rspec.md
Created June 4, 2018 05:50 — forked from supertopher/rspec.md
rspec best practices

Automated Testing.

Testing is helpful for ensuring that your code runs (driver code). This is to make sure that current features work, old features still work, and future work will be easily tested. By default, every Rails application has three environments: development, test, and production.

Rails offers three kinds of testing:

  • Unit tests: 
In the context of Rails, unit tests are meant primarily to cover the domain logic in your models, which include things like validations, calculations, search methods, and any other interesting functionality that your models implement.
  • Functional tests: These provide a way to verify that the actions for a single controller are working as expected, and allow you to do things such as post data to a specific action and verify the correct response is returned
  • Integration tests: Any given session with a Rails application will span across several models and controllers. Integration tests provide a way to test those kinds of interactions. Essentia
@liuzxc
liuzxc / .rubocop.yml
Created May 10, 2018 09:33 — forked from jhass/.rubocop.yml
My preferred Rubocop config
AllCops:
RunRailsCops: true
# Commonly used screens these days easily fit more than 80 characters.
Metrics/LineLength:
Max: 120
# Too short methods lead to extraction of single-use methods, which can make
# the code easier to read (by naming things), but can also clutter the class
Metrics/MethodLength:
@liuzxc
liuzxc / .rubocop.yml
Created May 10, 2018 09:33 — forked from jhass/.rubocop.yml
My preferred Rubocop config
AllCops:
RunRailsCops: true
# Commonly used screens these days easily fit more than 80 characters.
Metrics/LineLength:
Max: 120
# Too short methods lead to extraction of single-use methods, which can make
# the code easier to read (by naming things), but can also clutter the class
Metrics/MethodLength:
@liuzxc
liuzxc / docker-compose.yml
Created January 31, 2018 15:08 — forked from dudleycarr/docker-compose.yml
Docker Compose for nsq, StatsD, Graphite, and Grafana
graphitestatsd:
image: hopsoft/graphite-statsd
expose:
- 80
- 8125/udp
ports:
- 8080:80
nsqlookupd:
@liuzxc
liuzxc / consumer.go
Last active January 31, 2018 08:03 — forked from ebenoist/consumer.go
nsq consumer
package main
import (
"errors"
"log"
"os"
"os/signal"
"syscall"
"github.com/nsqio/go-nsq"
@liuzxc
liuzxc / goto-sublime
Created February 9, 2017 02:45 — forked from kendellfab/goto-sublime
Add mouse click `goto definition` in sublime text 3.
Linux - create "Default (Linux).sublime-mousemap" in ~/.config/sublime-text-3/Packages/User
Mac - create "Default (OSX).sublime-mousemap" in ~/Library/Application Support/Sublime Text 3/Packages/User
Win - create "Default (Windows).sublime-mousemap" in %appdata%\Sublime Text 3\Packages\User
[
{
"button": "button1",
"count": 1,
"modifiers": ["ctrl"],
"press_command": "drag_select",
@liuzxc
liuzxc / load_test_data.sh
Created March 19, 2016 03:36 — forked from clintongormley/load_test_data.sh
Run these commands in your shell to setup the test data for Chapter 5
curl -XPUT 'http://localhost:9200/us/user/1?pretty=1' -d '
{
"email" : "john@smith.com",
"name" : "John Smith",
"username" : "@john"
}
'
curl -XPUT 'http://localhost:9200/gb/user/2?pretty=1' -d '
{