Skip to content

Instantly share code, notes, and snippets.

@nuweb
nuweb / rebasing.txt
Created October 20, 2015 20:28
Git Rebasing and Squash Commits
1. Branch off of develop.
$ git checkout -b feature/myfeature develop
2. Squash commits into one commit
Open github and figure out how many commits to go back
$ git rebase -i head~(number of commits)
- You can remove commits in editor by doing {command K}.
- Save!
3. Checkout develop and make sure it's up to date
$ git checkout develop
$ git pull
@nuweb
nuweb / script-css-loader.js
Last active August 29, 2015 14:23
Asynchronous script and/or stylesheet loader
!function() {
"use strict";
var loader = function(assets) {
if (Object.prototype.toString.call(assets) !== "[object Array]" && assets.length < 1) {
return;
}
// get asset
var assetSrc = assets.shift();
// determine asset type
var assetType = (assetSrc.indexOf(".css") !== -1) ? "script" : "style";
@nuweb
nuweb / filter-map-reduce.js
Last active August 29, 2015 14:23
Higher order functions in JavaScript
var animals = [
{ name: "Waffles", type: "dog", age: 12 },
{ name: "Fluffy", type: "cat", age: 14 },
{ name: "Spelunky", type: "dog", age: 4 },
{ name: "Hank", type: "dog", age: 11 }
];
// filter dogs
animals = animals.filter(function(animal) {
return animal.type === "dog";
@nuweb
nuweb / angularjs-todo.js
Created June 19, 2015 01:28
AngularJS Todo App
angular.module("myApp", [])
.controller("TodoCtrl", ["$scope", function($scope){
// clear input todo text
$scope.lastTodoClass = "odd";
$scope.todoText = "";
// default todos
$scope.todos = [
{text:'Learn AngularJS', done:false, class:"even"},
{text: 'Build an app', done:false, class:"odd"}
];
@nuweb
nuweb / umd-module.js
Created June 16, 2015 14:28
A barebones UMD implementation
// A barebones UMD implementation
;(function(){
"use strict";
var myObj = {};
myObj.property = "prop";
myObj.method = function method() {};
// normalize for different environments
if (typeof define === "function" && define.amd) {
define(function() { return myObj; });
} else if (module && module.exports) {
@nuweb
nuweb / anagrams.js
Last active August 29, 2015 14:19
JavaScript Anagram
// Tell if given strings are anagrams without using any API methods except split
function anagrams(str1, str2) {
str1 = str1.split("");
str2 = str2.split("");
var charLen = [];
var anagram = false;
if(str1.length !== str2.length) {
@nuweb
nuweb / unique-letters-in-a-string.js
Last active August 29, 2015 14:07
Unique letters in a string using reduce
function getLetterCount(arr){
return arr.reduce(function(prev,next){
prev[next] = (prev[next] + 1) || 1;
console.log(prev[next]);
return prev;
},{});
}
var str = "dfdddf";
@nuweb
nuweb / prototypal-inheritance.js
Last active October 27, 2015 17:05
Setting up prototypal inheritance in JavaScript
var Animal = {
type: 'mammal',
legs: 4,
eyes: ['blue', 'black', 'brown'],
saying: ''
};
console.log(Animal.constructor); // Refers to the constructor method on the Object
Animal.prototype = {
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="[add your bin description]" />
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
</body>
@nuweb
nuweb / increment-large-nos.js
Last active December 14, 2015 18:39
A CodePen by nuweb. Increment large numbers in JavaScript
// increment/decrement large integers in JavaScript
var num = "900719925474599945678999";
function incdecLargeInt(str, operation){
var arr = str.split("");
var lastInt = Number(arr.pop());
if(lastInt===9){
// implement carry over
fixCarryOver(num.split(''));
var zx = res.reverse().join('');
// edge case when all are '9's