Skip to content

Instantly share code, notes, and snippets.

View schnogz's full-sized avatar

Andrew Schneider schnogz

View GitHub Profile

Keybase proof

I hereby claim:

  • I am schnogz on github.
  • I am schnogz (https://keybase.io/schnogz) on keybase.
  • I have a public key ASAjhp1sVkgvmYvM0FWlF1ypj2RFzShmRq2NO4xz2k0_Ego

To claim this, I am signing this object:

@schnogz
schnogz / 00_change_npm_permissions.config
Last active March 1, 2019 22:07
AWS Beanstalk config files
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/00_set_tmp_permissions.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
chown -R nodejs:nodejs /tmp/.npm
@schnogz
schnogz / .bowerrc
Last active March 1, 2017 04:02
RazPi-Electron-Snippets
{
"directory": "public/bower_modules/"
}
@schnogz
schnogz / jquery-example.js
Last active October 28, 2015 20:34
monkey patching
// create a closure and remap jQuery to $
(function($){
// save off original method
var _originalAppendTo = $.fn.appendTo;
// override method
$.fn.appendTo = function() {
// silly code to alternate backgound color
if ($(document.body).children().length % 2) {
document.body.style.background = "#f285cf";
@schnogz
schnogz / basic-constructor-function-mixed.js
Last active August 29, 2015 14:25
methods within constructor vs prototype in javascript
function Dog (name, breed) {
// instance variables
this.name = name;
this.breed = breed;
var medicalRecords = {
"hasWorms": true,
"hasDiabetes": false
};
@schnogz
schnogz / humorous-code-comments.js
Last active November 16, 2016 06:13
Top 15: Best source code comments
======================================================
// The magnitude of this hack compares favorably with that of the US national debt.
======================================================
// Warning: Thar be dragons lurkin and black magic at work here.
// Modify at your own risk!
//
// ^ ^
@schnogz
schnogz / always-use-semicolons-example1.js
Last active August 29, 2015 14:23
Why semicolons should be used in JavaScript
// The following results in a syntax error.
var a = 'a'
[].forEach.call(document.querySelectorAll('.md'), function(e) {
console.log(e);
});
// Adding the semicolon and now everything works just fine.
var a = 'a';
[].forEach.call(document.querySelectorAll('.md'), function(e) {
console.log(e);
@schnogz
schnogz / backbone-widget-view.js
Last active August 29, 2015 14:21
Spying on backbone.js view methods with Sinon.js
define([
'text!./Templates/mainTemplate.html',
'text!./Templates/messageTemplate.html'
], function (
maintemplate,
messageTemplate
) {
'use strict';
@schnogz
schnogz / duck-typing-example.js
Created May 17, 2015 18:10
JavaScript Duck Typing Example
function Animal(hasFeathers, sound) {
this.hasFeathers = hasFeathers;
this.sound = sound;
}
Animal.prototype.isDuck = function() {
if (this.hasFeathers && this.sound === "Quack") {
console.log("I am a duck");
} else {
console.log("I am not a duck");
}
@schnogz
schnogz / isArray-implementation-attemps.js
Last active December 27, 2023 08:13
JavaScript .isArray Implementations
// Attempt #1: using typeof
// fails in all cases since typeof [] returns "object"
Array.prototype.isArray = function(obj) {
return (typeof obj === "array");
}
// Attempt #2: using instanceof
// fails when obj = Array.prototype
// and when array is defined in another window or frame
Array.prototype.isArray = function(obj) {