Skip to content

Instantly share code, notes, and snippets.

View timnew's full-sized avatar

TimNew timnew

View GitHub Profile
@timnew
timnew / replace_text_in_clipboard.sh
Created September 18, 2017 05:40
Automatically replace text in clipboard
while true; do pbpaste | sed -e "s/name:production-db/\$server-master/g" | sed -e "s/name:production-replicadb/\$server-replica/g" | pbcopy; sleep 1; done
@timnew
timnew / chinese_spam_filter.rb
Created September 7, 2017 02:13
A spam filter targeting on Chinese spammers!
class ChineseSpamFilter
class << self
def spam?(job)
tencent_email?(job.email) &&
(
in_cjk?(job.title, 0.2) ||
in_cjk?(job.company, 0.2)
)
end
@timnew
timnew / Profile.bash
Created August 8, 2017 06:23
Git Clean Squashed
git-clean-squashed='git checkout -q master && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base master $branch) && [[ $(git cherry master $(git commit-tree $(git rev-parse $branch^{tree}) -p $mergeBase -m _)) == "-"* ]] && git branch -D $branch; done'
@timnew
timnew / 职称资格考试浏览器兼容性脚本.md
Last active March 20, 2016 14:22
职称资格考试浏览器兼容性脚本

http://ccatmc.com.cn/whb/cms/

  1. 登录页,需要干掉验证脚本
  2. 主页面需要去掉Frameset,单独打开iFrame
  3. 覆写报名页的脚本,修复各种兼容性问题
  4. 复写弹出页的脚本,填写完成后,读取 Console 中的 window.returnResult
  5. 报名页中调用 renderSubject(returnResult)
  6. 打印页没有savePdf脚本,直接打开iframe并保存为pdf
@timnew
timnew / ObservableMonitor.js
Last active March 15, 2016 11:39
RxJS Test Helper
class ObservableMonitor {
constructor(observable) {
this.observable = observable
this.promise = observable.materialize().toArray().toPromise()
}
complete(subject = this.observable) {
subject.onCompleted()
return this
@timnew
timnew / aggregation
Created February 5, 2015 10:59
Convert `$time.utc` to YYYY-MM-dd format string in MongoDB aggregation
{
$concat: [
{ '$substr': [{ '$year': '$time.utc' }, 0, 4] },
'-',
{
'$cond': [
{ '$lte': [{'$month': '$time.utc'}, 9] },
{ '$concat': ['0', { '$substr': [{ '$month': '$time.utc' }, 0, 2] } ] },
{ '$substr': [{ '$month': '$time.utc' }, 0, 2] }
]
@timnew
timnew / private.xml
Last active August 29, 2015 14:10
Karabiner Mapping for KBT Race 2
<?xml version="1.0" ?>
<root>
<item>
<name>KBT Race2</name>
<item>
<name>Volume Control</name>
<appendix>Fn + F1 to Mute Key</appendix>
<appendix>Fn + F2 to Volume Down Key</appendix>
<appendix>Fn + F3 to Volume Up Key</appendix>
/*****************
* bossFight.js *
*****************
*
* NO FARTHER, DR. EVAL!!!!
* YOU WILL NOT GET OUT OF HERE ALIVE!!!!
* IT'S TIME YOU SEE MY TRUE FORM!!!!
* FACE MY ROBOT WRATH!!!!!
*/
/**********************
* superDrEvalBros.js *
**********************
*
* You're still here?! Well, Dr. Eval, let's see
* how well you can operate with one less dimension.
*
* Give up now. Unless you have a magic mushroom
* up your sleeve, it's all over.
*/
/****************************
* documentObjectMadness.js *
****************************
*
* I can't believe it! I can't believe you made it onto
* Department of Theoretical Computation's web server!
* YOU SHOULD HAVE BEEN DELETED! This shouldn't even be
* possible! What the hell were the IT folks thinking?
*
* No matter. I still have the Algorithm. That's the