Skip to content

Instantly share code, notes, and snippets.

View micahasmith's full-sized avatar

Micah Smith micahasmith

View GitHub Profile
@micahasmith
micahasmith / classic-DAL.cs
Created October 3, 2011 01:22
The Classic DAL in .NET
public class PeopleDAL
{
public DataSet Person_GetAll()
{
//Returns a DataSet containing all people records in the database.
}
public DataSet Person_GetByPersonID(int personID)
{
@micahasmith
micahasmith / PeopleRepository.cs
Created October 3, 2011 01:29
The Repository Pattern in .NET
public class PeopleRepository
{
public List<PersonDTO> Get()
{
//return a list of person data transfer objects here
}
public void Insert(PersonDTO person)
{
//insert a person here
@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 / gist:1484274
Created December 16, 2011 03:17
d3.js simple example
//grab all divs on the page
//and set their width to 300
d3.selectAll('div')
.attr("width",300)
.attr("height",400);
@micahasmith
micahasmith / gist:1484318
Created December 16, 2011 03:32
d3.js data example
//select all divs
d3.selectAll('div')
//map some data to those divs, in order that they were found in the DOM
.data(["hello","world","hi"])
//and now do something to the divs with that data
//perhaps, put the data in the divs
//so this function param "d" is actually the data for that div
.html(function(d) {
return d;
});
@micahasmith
micahasmith / d3-js-simple-example.html
Created December 16, 2011 03:41
d3.js simple animation/data example
<html>
<head>
<title>d3test</title>
<link href="bootstrap-1.1.0.min.css" type="text/css"></link>
<script src="d3.min.js" type="text/javascript"></script>
</head>
<body>
<div id="demo">
<svg id="svgdemo"></svg>
</div>
@micahasmith
micahasmith / d3-js-enter.js
Created December 17, 2011 21:19
d3.js enter example
//so there's two divs on the page for this to select
d3.select('body')
.selectAll('div')
.data(["hello","there","world"])
//this will map "hello" and "there" to the only two divs
.html(function(d){return d;})
//but theres 3 pieces of data...?
//this is why d3 has the enter() function
//think of it as "withTheLeftOverDataAfterMapping()" instead of "enter()"
.enter()
@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 / hogan-express.js
Created December 23, 2011 21:28
hogan.js express.js view engine adapter
var HoganExpressAdapter=(function(){
var init=function(hogan) {
var compile=function(source){
return function(options) {
return hogan.compile(source).render(options);
};
}
return {compile:compile};
};
return {init:init};