Skip to content

Instantly share code, notes, and snippets.

View prettycode's full-sized avatar

Chris prettycode

  • Seattle, WA
View GitHub Profile
@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 / 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 / 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 / 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 / EventLogProgram.cs
Created May 8, 2013 02:43
Monitor for new Event Log entries. Basic proof-of-concept C# console app.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Threading;
using System.Security.Cryptography;
using System.Xml.Linq;
using System.Security;
@prettycode
prettycode / toast.js
Last active December 16, 2015 23:59
Create toast with Windows.UI (Windows 8 JavaScript app).
// 1
(function(undefined) {
"use strict";
var Notifications = Windows.UI.Notifications;
var Xml = Windows.Data.Xml;
var ToastController = {
configToXML: function(config) {
config.version = config.version || "1";
@prettycode
prettycode / CryptoRandom.cs
Last active November 10, 2021 15:27
Cryptographically-strong random number generator in C#.
// Cryptographically-strong random number generator
// Source: MSDN Magazine > 2007 > September > .NET Matters: Tales from the CryptoRandom
// Source URL: http://msdn.microsoft.com/en-us/magazine/cc163367.aspx
// Authors: Stephen Toub & Shawn Farkas
public class CryptoRandom : Random
{
private RNGCryptoServiceProvider cryptoProvider = new RNGCryptoServiceProvider();
private byte[] uint32Buffer = new byte[4];
@prettycode
prettycode / textarea-maxlength.ie.shim.js
Last active August 23, 2023 14:48
jQuery shim for supporting <textarea> "maxlength" attribute in IE < 10.
// jQuery shim for supporting <textarea> `maxlength` attribute in IE < 10
// Author: Chris O'Brien, prettycode.org
// License: MIT
(function ($) {
// Target only IE browsers that don't support `maxlength`
if (typeof document.selection === 'undefined' ||
'maxLength' in document.createElement('textarea')
@prettycode
prettycode / fork-your-own-gist.js
Last active December 16, 2015 08:58
A function that forks a Gist. You can use this to fork your own Gists.
function forkGist(user, gist) {
var path = (arguments.length ? ('/' + user + '/' + gist) : location.pathname);
var form = document.createElement('form');
form.method = 'post';
form.action = 'https://gist.github.com' + path + '/fork',
form.submit();
}
// Paste into browser console when viewing a Gist (including your own) to fork it
forkGist();
@prettycode
prettycode / example-tests.js
Last active December 16, 2015 07:49
Module loader for testing
var example = {
//js: 'https://gist.github.com/prettycode/5401842/raw/example.js'
js: 'http://fiddle.jshell.net/js/heyoffline.js?StillNoSpring'
}
loadScript(example.js, {
document: {
createElement: function(tag) {
return {
setAttribute: function(key, value) {