Skip to content

Instantly share code, notes, and snippets.

@cdanyl
cdanyl / resources.js
Created September 7, 2016 12:27 — forked from brucecoddington/resources.js
Wrapping $resource with api and data services.
angular.module('app.resources', ['ngResource'])
.factory('api', function ($resource) {
var api = {
defaultConfig : {id: '@id'},
extraMethods: {
'update' : {
method: 'PUT'
}
@cdanyl
cdanyl / auth.js
Created September 4, 2016 16:06 — forked from dig3/auth.js
Angular.js ES6 Login example
'use strict';
const TOKEN_KEY = 'auth.token';
class AuthService {
constructor ($window) {
this.$window = $window;
}
isAuthenticated () {
@cdanyl
cdanyl / CreditCard.js
Created August 24, 2016 13:30
ng resource abstraction
(function () {
var CreditCard = function (resource) {
return resource.create('card/:id');
};
angular.module('myModule').factory('CreditCard', CreditCard);
}());
@cdanyl
cdanyl / angularjs_directive_attribute_explanation.md
Created August 23, 2016 20:10 — forked from CMCDragonkai/angularjs_directive_attribute_explanation.md
JS: AngularJS Directive Attribute Binding Explanation

AngularJS Directive Attribute Binding Explanation

When using directives, you often need to pass parameters to the directive. This can be done in several ways. The first 3 can be used whether scope is true or false. This is still a WIP, so validate for yourself.

  1. Raw Attribute Strings

    <div my-directive="some string" another-param="another string"></div>
@cdanyl
cdanyl / destructuring.js
Created August 18, 2016 07:41 — forked from mikaelbr/destructuring.js
Several demos and usages for ES6 destructuring. Runnable demos and slides about the same topic: http://git.mikaelb.net/presentations/bartjs/destructuring
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => {
return [1, 2, 3];
@cdanyl
cdanyl / arrayIterator.js
Last active August 13, 2016 10:45
Array Iterator in Javascript
/*************************************************************
* Adds iterator to javascript Arrays
*************************************************************/
/**
* Returns previous element in the iteration
* @return {[object]} [Returns null if iteration has not started or if limit has reached]
*/
Array.prototype.prev = function(){
if(isNaN(this.index) || this.index <=0){
// Create $resource singleton service with custom methods
// SERVICE DebugOrder
.factory('Order', ['$resource', '$http',
function ($resource, $http) {
return $resource(Prefs.getResourceBaseUrl() + '/api/orders/:_id', {}, {
'count': {method: 'PUT', params: {_id: 'count'}},
'distinct': {method: 'PUT', params: {_id: 'distinct'}},
'find': {method: 'PUT', params: {_id: 'find'}, isArray: true},
'group': {method: 'PUT', params: {_id: 'group'}, isArray: true},
@cdanyl
cdanyl / Dart Map List
Created July 10, 2014 14:10
Return modified version of List
/**
* Returns list of title pages without the backslash.
*/
List<String> getPageTitles(String pageManager) {
Map<String, Object> pageConfig = JSON.decode(pageManager);
return new List.from(pageConfig['pages'].map((page) => page.substring(1)));
}
@cdanyl
cdanyl / JS Websocket Testing
Created July 10, 2014 14:04
Testing Websocket server inside the Chrome Dev Tools
var ws = new WebSocket("ws://localhost:3000");
ws.onopen = function(e){ console.log("Connected..."); }
ws.onclose = function(e){ console.log("Disconnected."); }
ws.onerror = function(e){ console.log("ERROR: " + e.data); }
ws.onmessage = function(e){ console.log("Message: " + e.data); }
ws.send("howdy!")