Skip to content

Instantly share code, notes, and snippets.

View prettycode's full-sized avatar

Chris prettycode

  • Seattle, WA
View GitHub Profile
@prettycode
prettycode / google-analytics-wrapper.js
Last active December 17, 2015 15:29
Simple wrapper for Google Analytics. Experimental instance pattern.
function Analytics(config) {
config = config || {};
var ga = (_gaq || []),
accountKey,
domainName,
proto = (this.prototype = Object.prototype);
proto.accountKey = function() {
if (!arguments.length) {
@prettycode
prettycode / actionCount.cs
Created May 25, 2013 07:19
Count the number of distinct Controller actions in an ASP.NET MVC application.
var actionCount = typeof(/*Some Controller Type In Your MVC App*/)
.Assembly.GetTypes()
.Where(t => typeof(Controller).IsAssignableFrom(t))
.Where(t => t.Namespace.StartsWith("AwesomeProduct.Web"))
.SelectMany(t => t.GetMethods(BindingFlags.Public | BindingFlags.Instance))
.Where(m => typeof(ActionResult).IsAssignableFrom(m.ReturnType))
.Where(m => !m.IsAbstract)
.Where(m => m.GetCustomAttribute<NonActionAttribute>() == null)
.Count();
@prettycode
prettycode / NetworkStreamExtensions.cs
Last active December 18, 2015 00:18
Utility functions for NetworkStream reading operations.
using System;
using System.IO;
using System.Net.Sockets;
namespace prettycode.org
{
// Author: Chris O'Brien, prettycode.org
public static class NetworkStreamExtensions
{
@prettycode
prettycode / article.htm
Created June 3, 2013 14:49
HTML layout with paper-page styling.
<!doctype html>
<html>
<head>
<title></title>
<style>
body {
width: 100%;
padding: 0;
margin: 0;
background-color: #F0F0F0;
@prettycode
prettycode / data-service-pattern.js
Last active August 29, 2015 14:10
AngularJS Data Service pattern
// a la http://chariotsolutions.com/blog/post/angularjs-corner-using-promises-q-handle-asynchronous-calls/
// http://www.webdeveasy.com/interceptors-in-angularjs-and-useful-examples/
angular
.module('movie')
.factory('movieService', function ($http, $log, $q) {
return {
getMovie: function (movie) {
var deferred = $q.defer();
@prettycode
prettycode / highcharts-and-highstock-angular-wrapper.htm
Last active August 29, 2015 14:10
Minimalist Highcharts + Highstock AngularJS Wrapper
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sandbox</title>
<script src="//code.jquery.com/jquery-2.1.1.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.js"></script>
<script src="//code.highcharts.com/stock/highstock.src.js"></script>
</head>
<body ng-app="app">
@prettycode
prettycode / angularjs-string-formatter-service.js
Last active October 24, 2015 04:02
Convenient String Formatter Helper/Utility Service Function in Angular JS
.factory('formatString', [function() {
/* by Chris O'Brien, prettycode.org, MIT license */
return function formatString() {
var args = Array.prototype.slice.call(arguments),
format = args.shift(),
match;
if (args.length === 1 && typeof args[0] === 'object') {
args = args[0];
}
@prettycode
prettycode / angular-template.htm
Created December 3, 2014 19:06
AngularJS template
<!doctype html>
<html lang="en" ng-app="app">
<head>
<meta charset="UTF-8">
<title>Sandbox</title>
<script src="//code.jquery.com/jquery-2.1.1.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.js"></script>
</head>
<body>
<div ng-controller="sandboxCtrl as sandbox">
@prettycode
prettycode / gulpCountFiles.js
Last active August 29, 2015 14:16
Output number of files in gulp.
function count(type) {
var counter = 0;
return through(function countFiles(data) {
counter++;
this.queue(data);
}, function endStream() {
console.log(' ' + counter + ' ' + type + ' files processed');
this.queue(null);
});
}
@prettycode
prettycode / beep.js
Last active August 29, 2015 14:17
Beep function that returns a promise when its done, for Node.js.
// problem: beeper uses setTimeouts() for multiple beeps yet has no callback
// solution: return a promise for when beeping is done
var beeper = require('beeper'),
_ = require('lodash'),
q = require('q')
;
function beep(count) {
return q.all(_.times(typeof count === 'undefined' ? 1 : count, function (n) {