Skip to content

Instantly share code, notes, and snippets.

View matthewpalmer's full-sized avatar

Matthew Palmer matthewpalmer

View GitHub Profile
<script type="text/javascript">
analytics.track('Page viewed', {
date: new Date()
});
</script>
<a id="linkTest">Click me!</a>
<script type="text/javascript">
analytics.trackLink($("#linkTest"), 'Post link clicked');
</script>
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<!-- REPLACE WITH THE CODE FROM YOUR SEGMENT.IO INSTRUCTIONS -->
<script type="text/javascript">
var analytics=analytics||[];analytics.load=function(e){var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src=("https:"===document.location.protocol?"https://":"http://")+"d2dq2ahtl5zl1z.cloudfront.net/analytics.js/v1/"+e+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n);var r=function(e){return function(){analytics.push([e].concat(Array.prototype.slice.call(arguments,0)))}},i=["identify","track","trackLink","trackForm","trackClick","trackSubmit","pageview","ab","alias","ready"];for(var s=0;s<i.length;s++)analytics[i[s]]=r(i[s])};
analytics.load("");
var post = document.getElementById('postTitle');
var postTitle = post.innerHTML;
analytics.track('Post page viewed', {
date: new Date(),
title: postTitle
});
module.exports = function (a,b) {
return a + b;
}
var assert = require('assert');
var expect = require('expect.js');
var add = require('../add');
describe('add',function() {
it('should expose a function', function() {
expect(add).to.be.a('function');
});
it ('should add the values', function() {
expect(add(1,3)).to.equal(4);
@matthewpalmer
matthewpalmer / terminalcommands.md
Last active December 17, 2015 05:39
Useful Terminal commands I can't remember

Curl

Use postdata npm module to extract the post data on the server. Use -k for https, -u for auth.

curl --data "param1=value1&param2=value2" https://localhost:3000/user/re
curl --data "param1=value1&param2=value2" -k -X POST https://localhost:3000/user/re
curl --form "fileupload=@filename.txt" https://localhost:3000/user/re
curl -u myusername:mypassword http://somesite.com

Git

@matthewpalmer
matthewpalmer / index.js
Created May 12, 2013 05:56
List all the items in a remote mongodb database
var MongoClient = require('mongodb').MongoClient;
function get(callback) {
MongoClient.connect('DBURL', function(err, db) {
var collection = db.collection('users');
var cursor = collection.find({});
cursor.each(function(a,b) {
console.log('response:', a, b);
});
@matthewpalmer
matthewpalmer / gist:7262751
Created November 1, 2013 09:02
Tab past closing brackets in sublime text 2
{ "keys": ["enter"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
[
{ "key": "following_text", "operator": "regex_contains", "operand": "^[)\"\\]]", "match_all": true },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
]
}
@matthewpalmer
matthewpalmer / gist:7271965
Created November 1, 2013 21:07
--save-dev
bower install angular --save-dev