Skip to content

Instantly share code, notes, and snippets.

View micahasmith's full-sized avatar

Micah Smith micahasmith

View GitHub Profile
@micahasmith
micahasmith / process-async-await.cs
Created March 4, 2013 19:51
.NET Process via Async/Await
public class Runner
{
public async Task<RunResults> Run(ProcessStartInfo info)
{
var process = new Process();
var runResults = new RunResults();
//some defaults that HAVE to be in place
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Data;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using System.Reactive.Linq;
@micahasmith
micahasmith / PeopleRepository.js
Created October 3, 2011 01:43
The Repository Pattern in JavaScript
function PeopleRepository() {
//when using constructor functions like this one to create objects in js,
//always make sure you're doing so with the new keyword
//or the scope will be off
//
//like so:
if(!(this instanceof PeopleRepository) {
return new PeopleRepository();
//we just enforced new
}
@micahasmith
micahasmith / ckeditor-selection-wrap-with-rangy.js
Created November 11, 2011 20:08
Wrap a selection in CKEditor with Rangy
/**
* allows you to wrap or insert an html tag over a selection/range using rangy
* @param iframe the CKEditor iframe html element
* @param tagName string representation of the tag, such as 'a' for anchor
* @param withNodeFunc function to allow outside modification of the element before injecting/wrapping
*/
function wrapOrInsert(iframe, tagName, withNodeFunc) {
var iframedoc = iframe.contentDocument || iframe.contentWindow.document,
tag = iframedoc.createElement(tagName),
selection = rangy.getIframeSelection(iframe),
@micahasmith
micahasmith / RxTcpServer.cs
Created May 7, 2012 03:19
rx c# tcp server
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Data;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using System.Reactive.Linq;
@micahasmith
micahasmith / html5-vid.sh
Created December 23, 2011 16:21
ffmpeg html5 video maker script
#!/bin/bash
# html5 videos maker
ffmpeg -i $1 -b 1500k -vcodec libx264 -g 30 -s 640x360 $1.mp4
ffmpeg -i $1 -b 1500k -vcodec libvpx -acodec libvorbis -ab 55000 -f webm -g 30 -s 640x360 $1.webm
ffmpeg -i $1 -b 1500k -vcodec libtheora -acodec libvorbis -ab 55000 -g 30 -s 640x360 $1.ogv
@micahasmith
micahasmith / img-layer-example.json
Created April 10, 2013 18:31
image layer example
{
"name":"image",
"settings":{
"uri":"http://localhost:8888/out.jpg"
"index":0
},
"commands":[
{ "name":"resize", "args":{"width":100,"height":300} },
{ "name":"combine", "args":{"map":""} }
]
@micahasmith
micahasmith / object.cshtml
Created November 6, 2012 18:19
Quick object in C#
@{
object copy = new
{
year = Model.Element("CopyrightDate").Content.Value,
school = Model.Element("SchoolName").Content.Value,
address = Model.Element("SchoolAddress").Content.Value,
city = Model.Element("SchoolCity").Content.Value,
state = Model.Element("SchoolState").Content.Value,
phone1 = Model.Element("SchoolPhonePrimary").Content.Value,
phone2 = Model.Element("SchoolPhoneSecondary").Content.Value
@micahasmith
micahasmith / WagStackAsyncRepository.cs
Created October 5, 2012 01:29
TPL Async Db w/ ServiceStack and Insight.Database
/* WagStack
*
* TPL Async DAL using ServiceStack's Expression/SQL Building
* and Insight.Database's async features
*/
public class WagStackAsyncRepository<T>:IAsyncRepository<T>
{
static WagStackAsyncRepository()
@micahasmith
micahasmith / grunt-livescript-mocha-example.js
Created August 19, 2012 17:05
Grunt Livescript Mocha Example
/*global module:false*/
module.exports = function(grunt) {
var log = grunt.log;
//grunt.loadTasks('grunt/tasks');
function handleResult(from, dest, err, stdout, code, done) {
if(err){
grunt.helper('growl', 'ERROR', stdout);
log.writeln(from + ': failed to compile to ' + dest + '.');
log.writeln(stdout);