Skip to content

Instantly share code, notes, and snippets.

View BrianGenisio's full-sized avatar

Brian Genisio BrianGenisio

View GitHub Profile
@BrianGenisio
BrianGenisio / bot.js
Created November 1, 2014 18:18
Example of controlling an Omni-directional robot (Alf) with Johnny-Five
var five = require("johnny-five");
var ports = [
{ id: "Alf", port: "/dev/tty.Alf-DevB"},
{ id: "Joystick", port: "/dev/tty.usbmodem1451" }
];
var boards = five.Boards(ports);
var normalizedPosition = { x: 0, y: 0 };
@BrianGenisio
BrianGenisio / gruntfile.js
Created September 9, 2014 16:02
Automatically wrapping files in IIFEs
grunt.initConfig({
concat: {
dist: {
src: ['src/*.js'],
dest: 'dist/app.js',
options: {
process: wrapInIIFE
}
},
},
App.factory('rickAstley', function() {
var messages = [
'Never gonna give you up',
'Never gonna let you down',
'Never gonna run around and desert you',
'Never gonna make you cry',
'Never gonna say goodbye',
'Never gonna tell a lie and hurt you'
];
<div ng-click="toggle()" class="hampster-dance">
<img src="/img/hampster.jpeg" ng-show="!animated" />
<img src="/img/animated-hampster.gif" ng-show="animated" />
<embed src="/audio/hampster-dance.wav" ng-show="animated">
</div>
public class VariablesController : ApiController
{
public IEnumerable<Variable> Get()
{
// get all
}
[Route("api/variables/{id}")]
public Variable Get( int id )
{
@BrianGenisio
BrianGenisio / gist:7762594
Created December 3, 2013 01:51
What does the fox say?
App.directive('whatDoesTheFoxSay', function() {
return {
link: function(scope, element, attrs) {
scope.message = "What does the fox say?";
element.click(function() {
scope.$apply(function() {
scope.message = "Wa-pa-pa-pa-pa-pa-pow!";
});
});
@BrianGenisio
BrianGenisio / gist:7544146
Created November 19, 2013 11:40
Get the number of watchers in your current page. >2000 is considered too high by many. I find this useful for perf tuning.
_($('.ng-scope'))
.map(function(scopeElement) { return angular.element(scopeElement).scope().$$watchers; })
.flatten(true)
.uniq()
.filter(function(x) { return !!x; })
.value()
.length;
@BrianGenisio
BrianGenisio / gist:6621396
Created September 19, 2013 10:00
ng-if modified to not create a child scope. (note my-if)
app.directive('myIf', ['$animate', function($animate) {
return {
transclude: 'element',
priority: 1000,
terminal: true,
restrict: 'A',
compile: function (element, attr, transclude) {
return function ($scope, $element, $attr) {
var childElement, childScope;
$scope.$watch($attr.myIf, function ngIfWatchAction(value) {
module.config(function($templateCache) {
$templateCache.put('template.html', '<b>Bad ass</b> template');
});
@BrianGenisio
BrianGenisio / gist:6299303
Last active December 21, 2015 11:29
The default behavior is to reject the error. If you don't do that, you are hiding the error condition.
angular.module('httpProgress')
.factory('httpProgressInterceptor', function($q) {
var requestCount = 0;
function updateProgress(update) {
var previous = requestCount;
requestCount += update;
if(previous <= 0 && requestCount > 0) {
NProgress.start();