Skip to content

Instantly share code, notes, and snippets.

Avatar

Donny donnior

View GitHub Profile
@donnior
donnior / logback.xml
Created Jun 24, 2019
For one package with logback, error only for console appender, but support info for file appender.
View logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<appender name="ErrorOnlyConsole" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
View git_code_count.md

统计每个人增删行数

git log --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -; done

添加或修改的代码行数

View replace_tab_with_spaces.sh
find . -name '*.java' ! -type d -exec bash -c 'expand -t 4 "$0" > /tmp/e && mv /tmp/e "$0"' {} \;
@donnior
donnior / LockVsAtomic.java
Last active Dec 25, 2015
Benchmark for safe incrementing a long value with Lock And Atomic
View LockVsAtomic.java
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.ReentrantLock;
public class LockVsAtomic {
protected final ReentrantLock lock = new ReentrantLock();
private volatile long l1 = 0l;
private AtomicLong l2 = new AtomicLong(0l);
@donnior
donnior / gist:4123259
Created Nov 21, 2012 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts
View gist:4123259

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@donnior
donnior / syntax_highlighting.py
Created Feb 24, 2012 — forked from JeanMertz/syntax_highlighting.py
Ruby on Rails syntax highlight switcher for Sublime Text 2
View syntax_highlighting.py
import sublime, sublime_plugin
import os
class DetectFileTypeCommand(sublime_plugin.EventListener):
""" Detects current file type if the file's extension isn't conclusive """
""" Modified for Ruby on Rails and Sublime Text 2 """
""" Original pastie here: http://pastie.org/private/kz8gtts0cjcvkec0d4quqa """
def on_load(self, view):
filename = view.file_name()
@donnior
donnior / gist:1588907
Created Jan 10, 2012
add_iphone_view_support.rb
View gist:1588907
#config/initializers/mime_types.rb
Mime::Type.register_alias "text/html", :iphone
#Make a copy of app/views/layouts/application.html.erb calling it application.iphone.erb
#Make copies of the necessary view files in your controllers, calling them things like index.iphone.erb
#in Controller
respond_to :html, :iphone
@donnior
donnior / gist:1531947
Created Dec 29, 2011 — forked from JeffreyWay/gist:1525217
Instant Server for Current Directory
View gist:1531947
alias server='open http://localhost:8000 && python -m SimpleHTTPServer'
@donnior
donnior / How to change Application's language under Mac.applescript
Created Dec 16, 2011
How to change Application's language under Mac
View How to change Application's language under Mac.applescript
#change some specific application's interface language
defaults write com.google.Chrome AppleLanguages "(zh_CN,en_US)"
defaults write com.apple.iWork.Pages AppleLanguages "(zh_CN,en_US)"
defaults write com.apple.Aperture AppleLanguages "(zh_CN,en_US)"
#change all applications' interface language, don't recommend.
defaults write NSGlobalDomain AppleLanguages "(en_US,zh_CN)"
defaults write NSGlobalDomain AppleLanguages "(zh_CN,en_US)"
View Html Parse with Nokogiri.rb
require 'rubygems'
require 'nokogiri'
require 'open-uri'
user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.854.0 Safari/535.2"
html = "http://www.somedomain.com/somepage/"
@doc = Nokogiri::HTML(open(html, 'User-Agent' => user_agent), nil, "UTF-8")
@doc.xpath("//li[a[text()='Home']]/following-sibling::li").each do |link|
You can’t perform that action at this time.