Skip to content

Instantly share code, notes, and snippets.

@i3zhe
i3zhe / gist:6365778
Last active December 21, 2015 21:08
keep local forked repo upstream
https://help.github.com/articles/syncing-a-fork
```
git remote -v
git remote add upstream https://github.com/otheruser/repo.git
git fetch upstream
git checkout master
git merge upstream/master
```
@i3zhe
i3zhe / rmhistory
Created August 9, 2013 06:41
When accidentally pasting a file into the shell it puts a ton of ugly nonsense entries in the bash history. Is there a clean way to remove those entries?
rmhist() {
start=$1
end=$2
count=$(( end - start ))
while [ $count -ge 0 ] ; do
history -d $start
((count--))
done
}
@i3zhe
i3zhe / gist:6137823
Created August 2, 2013 06:13
In case git:// protocol blocked by company or not available to you for any reason, you can do this.
If this is an issue with your firewall blocking the git: protocol port (9418), then you should make a more persistent change so you don't have to remember to issue commands suggested by other posts for every git repo.
git config --global url."https://".insteadOf git://
This simply adds the following two lines to ~/.gitconfig:
[url "https://"]
insteadOf = git://
@i3zhe
i3zhe / restore_removed_path_in_git
Last active December 20, 2015 08:49
Restore a deleted file/path in a Git repo. I met a problem when upgrading a Rails 2 project to 3. I removed the images, javascripts and stylesheets dirs in the public/, and committed the change, but I accidentally forgot to move all the images to asset. So here's a quick way to restore the images I need.
`git rev-list -n 1 HEAD -- <file_path>`
Then checkout the version at the commit before.
`git checkout <deleting_commit>^ -- <file_path>`
Or in one command, if $file is the file in question.
`git checkout $(git rev-list -n 1 HEAD -- "$file")^ -- "$file"`
The solution works fine on bash, but zsh has it's own expansion on '^'. So simply replace '^' with '~1', ~X allows you to specify X commits before the specified commit, so ~1 is the commit before, ~2 is two commits before, etc
@i3zhe
i3zhe / gist:6085523
Created July 26, 2013 02:13
Add REMOVE_FROM_DOCK to your dock icon's context menu, and you can hide finder from there
f=/System/Library/CoreServices/Dock.app/Contents/Resources/DockMenus; sudo cp $f.plist $f-old.plist; sudo defaults write $f finder-running -array-add '<dict><key>command</key><integer>1004</integer><key>name</key><string>REMOVE_FR‌OM_DOCK</string></dict>'; sudo chmod 644 $f.plist; osascript -e 'quit app "Dock"'
@i3zhe
i3zhe / Preferences.sublime-settings
Created July 16, 2013 05:50
Sublime Text 3 Custom Settings
{
"color_scheme": "Packages/User/Tubnil.tmTheme",
"colored_folder_glyphs": true,
"font_size": 15,
"highlight_line": true,
"highlight_modified_tabs": true,
"ignored_packages":
[
"Vintage"
],
@i3zhe
i3zhe / Folder Preferences
Created July 14, 2012 12:31 — forked from chrisyour/Folder Preferences
Show hidden files and hidden folders (except .git) in your TextMate project drawer
# Want to show hidden files and folders in your TextMate project drawer? Simple, just modify the file and folder patterns in TextMate's preferences.
# Instructions:
# Go to TextMate > Preferences...
# Click Advanced
# Select Folder References
# Replace the following:
# File Pattern
@i3zhe
i3zhe / 12306.user.js
Created January 6, 2012 07:35 — forked from quietlynn/12306.user.js
12306 Auto Query => A javascript snippet to help you book ticket
/*
12306 Auto Query => A javascript snippet to help you book tickets online.
Copyright (C) 2011 Jingqin Lynn
Includes jQuery
Copyright 2011, John Resig
Dual licensed under the MIT or GPL Version 2 licenses.
http://jquery.org/license
Includes Sizzle.js