Skip to content

Instantly share code, notes, and snippets.

@panicbus
panicbus / eventemitter.js
Created October 20, 2016 18:33
Inheriting from EventEmitter using extends keyword and constructor() object
// in a greetr.js file //
////////////////////////
'use strict';
var EventEmitter = require('events');
// module.exports exports the class like any variable or function
// keyword extends removes the need for the Greetr function contructor
// and the need for util. inherits and the need for util = require('util')
@panicbus
panicbus / template-literal.js
Created October 20, 2016 18:32
Template literal syntax in Node
var name = 'John Doe';
// normal string
var greet = 'Hello ' + name;
// Template literal
var greet2 = `Hello ${ name }`;
// also add this in a seperate same-level jsconfig.js file to make sure Node compiles it correctly
@panicbus
panicbus / event-emitter.js
Created October 20, 2016 18:31
Event emitter property in Node
// Creating our own Emitter property //
//////////////////////////////////////
// if your using a core node property you don't need the ./ before the property
// ./ is if you're lookign for somethign on the same file level
// THIS FILE USES THE INTERNAL NODE EVENT EMITTER
var Emitter = require('events');
// events is the property of the config.js object you're looking for
var eventListener = require('./config').events;
var emtr = new Emitter();
@panicbus
panicbus / prototype-inheritances.js
Created October 20, 2016 18:30
Prototype inheritance examples
function Stars(name, hair, isSkinny){
this.name = name;
this.hair = hair;
this.isSkinny = isSkinny;
}
Stars.prototype.girl = function(){
if (this.isSkinny === true){
this.isSkinny = "Hell ya!"
} else {
@panicbus
panicbus / calc-age.js
Last active October 20, 2016 20:12
Calculate age -- also see http://codepen.io/panicbus/pen/ZpmZrb
var today = new Date();
var pastDate = new Date("10-28-70");
function calcDate(date1, date2) {
var diff = Math.floor(date1.getTime() - date2.getTime());
var day = 1000 * 60 * 60 * 24;
var days = Math.floor(diff / day);
var minutes = Math.floor(days * 24 * 60);
var hours = Math.floor(days * 24);
@panicbus
panicbus / new_gist_file_0
Created September 11, 2016 07:40
Sass & Stylus watch commands
$ stylus -w public/stylesheets/
$ sass --watch mySassFile.sass:myCssFile.css
@panicbus
panicbus / addingsass.md
Last active October 20, 2016 18:27
Add Sass to Node project - easily!

From an answer on Stack Overflow

You don't need to download and install libsass manually. It is installed with an implementer. I picked node-sass implementer because it is based on node.js.

Installing node-sass If you don't have npm, install Node.js first. To install node-sass globally [-g]:

$ npm install -g node-sass

@panicbus
panicbus / scrollhtml.htm
Last active August 29, 2015 13:58
Scroll HTML text
<div data-role="content" id="top"> <!-- anchor to scroll top-->
<a href="#Anchor" id="anchor1" class="anchorlink">Your anchor text</a>
<a name="Anchor" id="Anchor"></a>
<div>The Div to scroll to</div>
<a class="top" data-ajax="false" data-role="button" href="#top">TOP</a>
@panicbus
panicbus / scrolldown.js
Created April 8, 2014 16:25
JavaScript scrolldown
$('a').click(function(){
$('html, body').animate({
scrollTop: $( $(this).attr('href') ).offset().top - 100 //scrolls to anchor tag in body minus 100 px
}, 'slow');
return false;
});
@panicbus
panicbus / jsbin.qudiw.css
Last active October 20, 2016 18:50
Change the text in a box on click
#one {
height: 100px;
width: 100px;
background-color: red;
display: block;
margin: 10px;
padding: 20px;
color: white;
}