Skip to content

Instantly share code, notes, and snippets.

View AlphaNerd's full-sized avatar
💭
Nerding as always

J.Coleman AlphaNerd

💭
Nerding as always
View GitHub Profile
@AlphaNerd
AlphaNerd / Angular $AuthService Factory - Mockup
Created April 16, 2016 22:31
Simple mockup of Angularjs user authentication service/factory
.factory('$authservice', ['$window', '$localstorage', '$state', function($window, $localstorage, $state) {
// Access local storage for existing user info
var SHIFT = $localstorage.getObject("Shift")
// Does session exist?
if (SHIFT && SHIFT.session.token) {
console.log("$authservice: Existing Session found: ", [SHIFT])
} else {
console.log("$authservice: No session found.")
SHIFT = {
session: {
@AlphaNerd
AlphaNerd / localstorageService.js
Created April 16, 2016 22:38
Simple $localstorage service
angular.module('starter.services', [])
.factory('$localstorage', ['$window', function($window) {
return {
set: function(key, value) {
$window.localStorage[key] = value;
},
get: function(key, defaultValue) {
return $window.localStorage[key] || defaultValue;
},
setObject: function(key, value) {
@AlphaNerd
AlphaNerd / app.js
Created April 16, 2016 22:57
Solid framework for secure content, network connection status, and general route setup
// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'starter.controllers' is found in controllers.js
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'ngCordova'])
.run(function($ionicPlatform, $rootScope, $cordovaNetwork, $state, $authservice) {
$ionicPlatform.ready(function() {
@AlphaNerd
AlphaNerd / controller.js
Created April 20, 2016 11:33
Like/Unlike Button - Great for using localStorage data and using a service in backend to update server.
$scope.i = 0;
$scope.likeClick = function(data){
$scope.data[$scope.i].likes.byUser = $dataservice.likeClick(data);
}
@AlphaNerd
AlphaNerd / controllers.js
Created May 5, 2016 10:57
AngularJS promises in a nut shell. $q boilerplate
function TodoCtrl($scope, $q, $timeout) {
function createPromise(name, timeout, willSucceed) {
$scope[name] = 'Running';
var deferred = $q.defer();
$timeout(function() {
if (willSucceed) {
$scope[name] = 'Completed';
deferred.resolve(name);
} else {
$scope[name] = 'Failed';
@AlphaNerd
AlphaNerd / Array.Prototype.move.js
Created May 13, 2017 03:35
Move an item in Array from one position to another easily
Array.prototype.move = function (old_index, new_index) {
if (new_index >= this.length) {
var k = new_index - this.length;
while ((k--) + 1) {
this.push(undefined);
}
}
this.splice(new_index, 0, this.splice(old_index, 1)[0]);
return this; // for testing purposes
};
@AlphaNerd
AlphaNerd / swap.txt
Created January 8, 2018 16:25
Facebook Graph access_token; swap from Short Live to Long Live token
https://graph.facebook.com/oauth/access_token?client_id=<app_id>&client_secret=<app_secret>&grant_type=fb_exchange_token&fb_exchange_token=<token_to_exchange>
@AlphaNerd
AlphaNerd / index.html
Created July 31, 2018 11:50
Image Slider - Before & After Images
<figure>
<div id="twoface-demo"></div>
<figcaption>Before and after photos of Queensland</figcaption>
</figure>
@AlphaNerd
AlphaNerd / js
Created February 26, 2019 22:43
Content Editable Directive for Angular
angular.module('garago.directives.contenteditable', [])
.directive("contenteditable", function($timeout, $garagoAPI, $rootScope) {
function toInnerText(value) {
var tempEl = document.createElement('div'),
text;
tempEl.innerHTML = value;
text = tempEl.textContent || '';
return text.trim();
}
@AlphaNerd
AlphaNerd / highChartsDefaults.js
Created May 18, 2019 11:19
HighCharts basic defaults for Parakeeto data feed
this.defaultLargeChartOptions = {
chart: {
backgroundColor:'#f2f2f2'
},
credits: {
enabled: false
},
title : {
text : ''
},