Skip to content

Instantly share code, notes, and snippets.

@j127
j127 / node.js
Last active December 19, 2015 07:08
Node.js
// app.js
var express = require('express')
, routes = require('./routes')
, user = require('./routes/user')
, http = require('http')
, path = require('path')
// Include another file
, score = require('./routes/score');
app.get('/', routes.index);
@j127
j127 / Node.js Twit Module Example
Last active December 26, 2015 18:09
How to use the Twit module to search tweets: 1. Install Node.js 2. Make a new folder and open it in the terminal. 3. Type: npm install twit 4. Create a file called app.js just above the node_modules directory that was automatically created by the previous command 5. Paste the code in from this Gist. 6. Add your Twitter API keys to the file and s…
// Import the twit module that was downloaded with npm install twit.
// The module is loaded in node_modules and Node.js knows where to find it.
var Twit = require('twit');
// Settings -- put your keys here:
var T = new Twit({
consumer_key: '...',
consumer_secret: '...',
access_token: '...',
access_token_secret: '...'
@j127
j127 / Save Tweets to MongoDB
Last active December 26, 2015 18:09
Expanded version of this: https://gist.github.com/j127/7191906 -- just run npm install mongoose in the terminal to install the database stuff.
// Import the twit module that was downloaded with npm install twit.
// The module is loaded in node_modules and Node.js knows where to find it.
var Twit = require('twit');
// Import the MongoDB connection stuff
var mongoose = require('mongoose');
// Connect to the database - this also creates the database if it doesn't exist
mongoose.connect('mongodb://localhost/twittersearch');
$(document).ready(function() {
console.log('Document ready');
fetchEmployeeData();
function fetchEmployeeData() {
console.log('Running fetchEmployeeData()');
// Get JSON
$.ajax({
type: 'GET',
@j127
j127 / app-obj.js
Created October 30, 2013 17:50
Partial code only
function initLocalStorageControls() {
var userMessage, dataKey, dataValue, storedData, dataObj = {}, dataString = '', obj = {};
if (Modernizr.localstorage) {
console.log('Local storage is available');
$('form').fadeIn();
userMessage = 'Use the form below to add and display data.';
// Pre-fill form
storedData = localStorage.getItem('userData');
// Create a table and attach to the target div
myTable = $('<table><caption><thead><tbody>').appendTo('#myDiv');
// Loop through object and put the keys/values in table cells on the page
Object.keys(obj).forEach(function(key) {
if (obj[key] !== null) {
currentRow = $('<tr>');
cell1 = $('<td>').text(key).appendTo(currentRow);
cell2 = $('<td>').text(obj[key]).appendTo(currentRow);
currentRow.appendTo('tbody');
function Vehicle(manufacturer) {
this.manufacturer = manufacturer;
}
Vehicle.prototype.sayHello = function () {
alert('Hi there');
};
function Unicycle(manufacturer, spokes) {
Vehicle.call(this, manufacturer);
@j127
j127 / index-factory.html
Created November 5, 2013 18:12
Factory Pattern, JavaScript
<!DOCTYPE html>
<html>
<head>
<title>JS Design Patterns</title>
<meta charset="utf-8" />
</head>
<body>
<h1>Factory Pattern</h1>
<button id="buildCar">Build a car</button> <button id="buildMotorbike">Build a motorbike</button>
<!DOCTYPE html>
<html>
<head>
<title>JS Design Patterns</title>
<meta charset="utf-8" />
</head>
<body>
<h1>Singleton Pattern</h1>
<button id="createWorld">Create a World</button> <button id="createAnotherWorld">Create Another World</button>
@j127
j127 / Forum Error
Created June 6, 2014 18:58
Error page is noindexed with a meta tag.
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-ca">
<head>
<title>Something has gone wrong.</title>
<meta name="robots" content="noindex" />
<link rel="stylesheet" type="text/css" href="/applications/dashboard/design/error.css" /></head>
<body>
<div id="Content">
<div class="SplashInfo">
<h1>Something has gone wrong.</h1>