Skip to content

Instantly share code, notes, and snippets.

View peterheard01's full-sized avatar

Pete Heard peterheard01

View GitHub Profile
tree = new TreeModel();
root = tree.parse({
children: [
{
mobileTitle : 'Dashboard',
desktopTitle : 'My Sessions'
stateName : 'app.dashboard'
children: [
{
// how to reduce a list of tags using a filter command
['mice','hats','coats','hats'].reduce((curr,prev) => { if(curr.indexOf(prev) < 0){curr.push(prev)};return curr; },[])
1) nu-disco in the last day
https://soundcloud.com/search/sounds?q=nu%20disco&filter.created_at=last_day
2) auto-like everything
var list= document.getElementsByClassName("sc-button-like");
for (var i = 0; i < list.length; i++) {
if(!list[i].classList.contains('sc-button-selected')){
list[i].click();
}
// I think Ben's solution looks good although I probably wouldn't have used promises because
// I sometimes think the interface to them is confusing and you are locked into their interpretation not your own,
// If I did use them I would try and bury them behind my own interface. There are always going to be million
// different ways to do the same thing in angular so I try and model the problem in terms of OO design as opposed to
// language specific or angular specific, and of course making something easy to test is always my highest priorities.
// Coupling tests to promises is hard and they are difficult to read. So I would use promises in the background not in
// the foreground design.
// I have identified that we have 3 entities in this solution.
@peterheard01
peterheard01 / angularjs-modals.htm
Created March 23, 2016 11:30 — forked from bennadel/angularjs-modals.htm
Creating A Simple Modal System In AngularJS
<!doctype html>
<html ng-app="Demo">
<head>
<meta charset="utf-8" />
<title>
Creating A Simple Modal System In AngularJS
</title>
<link rel="stylesheet" type="text/css" href="./demo.css"></link>
function Person(){
var car = new Car();
}
function Car(){
//coupled
function main(userInputtedString, userInputtedBoolean, userInputtedInt){
var car = new Vehicle();
var bus = new Vehicle();
var plane = new Vehicle();
var vehicles = [car,bus,plane];
forEach(vehicle in vehicles){
@peterheard01
peterheard01 / test_double_spy_1.js
Last active March 18, 2016 07:57
Test Double : Dummy Object (Javascript)
//the real world implementation
function Alerter(){
this.alert = (msg){
window.alert(msg);
};
}
var Alerter = new Alerter();
//the Alerter is injected into here
@peterheard01
peterheard01 / stub_spy.js
Last active March 9, 2016 17:57
this is a spy test double in javascript
//original Code
function HttpAuthenticator($http){
this.load = (){
return $http.get('/api/login')
};
}
var Authenticator = new HttpAuthenticator();
//the controller which will attempt to log in when it is loaded
@peterheard01
peterheard01 / structure_coupling.js
Last active January 3, 2022 15:03
An example of coupling and decoupling in Javascript
//this type of coupling happens when you expose the internals object A to object B
//in this example we are accessing a method and assigning a property.
//this type of coupling happens when one module asks a question of another module
//if Person changes how it represents 'hasHobby' it breaks the coupled version in
//2 places
//by using a 3rd object to hold that information we only break the code in 1
//place if we ever change how the Person represents hwo they have a hobby
//coupled
function main(){