Skip to content

Instantly share code, notes, and snippets.

@IanBoyanZhang
IanBoyanZhang / first_test.js
Last active October 3, 2015 15:58
Minimal example of setting up a Chai/Mocha sandbox
describe("Vehicle", function() {
describe("constructor", function() {
it("should have a default type", function() {
var car = new Vehicle();
expect(car.type).to.equal("car");
});
});
});
awk '{print $7}' access.log | # Split by whitespace, 7th field is request path
sort | # Make occurrences of the same URL appear consecutively in file
uniq -c | # Replace consecutive occurrences of the same URL with a count
sort -rn | # Sort by number of occurrences, descending
head -n 5 # Output top 5 URLs
@jfeldstein
jfeldstein / get_campaigns.js
Created August 2, 2013 20:55
Persistent referrer and UTM campaign tracking for Segment.io
getReferrerTraits = function() {
// Requires: jQuery, jQuery.cookie, segment.io
// TODO: Update referralHost:blackList with your domain, so we only track external referrers.
var analytics_args = [],
analytics_traits,
acquisitionSource,
firstReferrer,
firstCampaign,
@adamjohnson
adamjohnson / publickey-git-error.markdown
Last active May 10, 2024 10:00
Fix "Permission denied (publickey)" error when pushing with Git

"Help, I keep getting a 'Permission Denied (publickey)' error when I push!"

This means, on your local machine, you haven't made any SSH keys. Not to worry. Here's how to fix:

  1. Open git bash (Use the Windows search. To find it, type "git bash") or the Mac Terminal. Pro Tip: You can use any *nix based command prompt (but not the default Windows Command Prompt!)
  2. Type cd ~/.ssh. This will take you to the root directory for Git (Likely C:\Users\[YOUR-USER-NAME]\.ssh\ on Windows)
  3. Within the .ssh folder, there should be these two files: id_rsa and id_rsa.pub. These are the files that tell your computer how to communicate with GitHub, BitBucket, or any other Git based service. Type ls to see a directory listing. If those two files don't show up, proceed to the next step. NOTE: Your SSH keys must be named id_rsa and id_rsa.pub in order for Git, GitHub, and BitBucket to recognize them by default.
  4. To create the SSH keys, type ssh-keygen -t rsa -C "your_email@example.com". Th
@faisalman
faisalman / baseConverter.js
Last active January 11, 2023 14:43
Convert From/To Binary/Decimal/Hexadecimal in JavaScript
/**
* Convert From/To Binary/Decimal/Hexadecimal in JavaScript
* https://gist.github.com/faisalman
*
* Copyright 2012-2015, Faisalman <fyzlman@gmail.com>
* Licensed under The MIT License
* http://www.opensource.org/licenses/mit-license
*/
(function(){
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"