Skip to content

Instantly share code, notes, and snippets.

View cgkio's full-sized avatar

Christian Kessler IV cgkio

View GitHub Profile
@cgkio
cgkio / jquery_ready.js
Created November 17, 2013 20:10
.ready (jQuery)
$(function() {
// Handler for .ready() called.
});
@cgkio
cgkio / resync_w_new_gitignore.sh
Created November 17, 2013 18:30
Resync/update git repo with new .gitignore
git rm -r --cached .
git add .
git commit -m ".gitignore is now working"
@cgkio
cgkio / node_install_priv.sh
Created November 15, 2013 21:09
Installing and uninstalling node.js without NVM
$ sudo chown -R $USER /usr/local
@cgkio
cgkio / force_https.js
Created November 15, 2013 20:53
Force HTTPS | redirect your clients to the HTTPS address when they make a request with HTTP
// http
var http = require('http');
var server = http.createServer(function (req, res) {
// optional, for HSTS
// see https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security
res.setHeader('Strict-Transport-Security', 'max-age=8640000; includeSubDomains');
if (req.headers['x-forwarded-proto'] !== 'https') {
var url = 'https://' + req.headers.host + '/';
@cgkio
cgkio / local_storage.js
Created November 15, 2013 02:17
Setting, getting and removing local storage
localStorage.setItem('favoriteflavor','vanilla');
var taste = localStorage.getItem('favoriteflavor');
localStorage.removeItem('favoriteflavor');
@cgkio
cgkio / git.sh
Created November 12, 2013 16:51
Setting up Git on EC2 to pull from GitHub repo
# Install git
sudo apt-get install git-core
# Set name for git to use when you commit
git config --global user.name "Your Name Here"
# Set email for git to use when you commit
git config --global user.email "[email protected]"
# Generate SSH deploy keys by following the instructions at:
@cgkio
cgkio / remove_offending_key.sh
Created November 12, 2013 16:05
Fix Offending key in ~/.ssh/known_hosts file
perl -pi -e 's/\Q$_// if ($. == 6);' ~/.ssh/known_hosts
# Note: Change the 6 according to the line number shown in the terminal error message
@cgkio
cgkio / parse_post.js
Created November 9, 2013 02:26
Post object with Parse JavaScript SDK
var PostObject = Parse.Object.extend("classnamegoeshere");
var postobject = new PostObject();
postobject.set("score", 1337);
postobject.set("playerName", $("#myFieldID").val());
postobject.set("cheatMode", false);
postobject.save(null, {
success: function(postobject) {
// The object was saved successfully.
@cgkio
cgkio / regex_between_quotes
Created November 7, 2013 17:12
Matches content between quotes (includes nested quotes)
([""'])(?:(?=(\\?))\2.)*?\1
@cgkio
cgkio / ajax_load_on_click.js
Created November 7, 2013 16:05
Simple jQuery AJAX load on #id click event
$("#target").click(function() {
$("#result").load("ajax/test.html");
});