Skip to content

Instantly share code, notes, and snippets.

@FrancoB411
Last active October 10, 2015 18:47
Show Gist options
  • Select an option

  • Save FrancoB411/3734728 to your computer and use it in GitHub Desktop.

Select an option

Save FrancoB411/3734728 to your computer and use it in GitHub Desktop.
Snippets
//JS
//===============================================================================
//Modal centering Script:
$('#YourModal').modal().css(
{
'margin-top': function () {
return window.pageYOffset-($(this).height() / 2 );
}
});
//Cycles through an array, starting again at the beginning when it hits the end.
cycle = (function() {
var pos = 0;
return {
next: function(array) { return pos = (pos + 1) % array.length}
}
})();
//Usage:
// someArray[cycle.next(someArray)]
//Reveal Password toggle.
//-------------------------------------------------
$(document).ready(function()
{
$("#password_checkbox").on( "click", function() {
revealPassword(this);
});
function revealPassword(el) {
var pw = $("#password_field")
var type = $(el).is(":checked") ? "text" : "password";
pw.get(0).type = type
}
});
//Usage:
// Give the checkbox id="password_checkbox"
// Give the password field id="password_field"
// That's it.
//Scroll to Anchor Target
//-------------------------------------------------
function scroller() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') || location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
};
// in the html:
<script type="text/javascript">
$(document).ready(scroller());
</script>
//Usage:
//Put the (document ready) function above in the HTML.
//If using asset pipeline, put the big function before that in the relevant controller.
//If not using asset pipeline, link the a js file with the former function in it.
//GIT COMMANDS.
//===============================================================================
// Git Bisect
git bisect start
git bisect bad
git bisect good <sha>
// Check staged files against last commit
git diff --cached
// Remove a file from staging
git rm --cached <file>
// Remove a file from staging
git reset HEAD <file>
// Undo uncommitted changes, revert to last commit
git add .
git reset --hard
// Unstage all files
git reset HEAD
// Show remote repo status
git remote show <branch>
// Edit last commit message
git commit --amend -m "your new message"
// View Staged Files
git status
// Push an old commit to Heroku master (the shaw is just a sample)
git push -f heroku 9f32361a64066d67ae0dda49fb4b84954af0693e:master
// show log history one line at a time
git log oneline
// show file changes in git log
git log -p
//show file changes in git log
git log -p -[number of commits to show]
ex:
git log -p -2
//git log with a list of modified files
git stat
//Add a remote tracking branch
git branch --track <branch name> origin/master
//git log with custom format
git log --pretty=format:"%h - %an, %ar : %s"
//list of custom format options
%H Commit hash
%h Abbreviated commit hash
%T Tree hash
%t Abbreviated tree hash
%P Parent hashes
%p Abbreviated parent hashes
%an Author name
%ae Author e-mail
%ad Author date (format respects the –date= option)
%ar Author date, relative
%cn Committer name
%ce Committer email
%cd Committer date
%cr Committer date, relative
%s Subject
//git command to display the commit graph
git log --oneline --graph
//verifies conflicts have been resolved
Git status
//git log option for shorter sha 1s (easier to copy paster, and remember)
--abbrev-commit
// git long since a date
git log --since 2012-11-01
// great resource for git commands
http://gitref.org/inspect/
// GIT_FLOW COMMANDS.
//===============================================================================
git-flow-init
git-flow-feature
git-flow-release
git-flow-hotfix
git-flow-support
git-flow-version
gitflow-common
gitflow-shFlags
//git flow options
list
start
publish
//finish
git flow feature finish [featureName]
//pull
git flow feature pull [alias] [featureName]
//SUBLIME COMMANDS.
//===============================================================================
//command palette
Command shift option p
//find file
Command T
//splits selection into lines
Command shift L
//selects multiple occurrences for words
Command shift D
//go to line
control G
//VIM COMMANDS.
//===============================================================================
//delete and copy line, normal mode:
dd
//paste normal mode:
p
//save normal mode:
:w
//quit normal mode:
:q
//split window normal mode:
:split
// Go to start of line normal mode:
0
// Go to end of line
$
//TERMINAL COMMANDS.
//===============================================================================
du -sh [directory-path] //shows you how much memory a file is using.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment