Skip to content

Instantly share code, notes, and snippets.

View micahasmith's full-sized avatar

Micah Smith micahasmith

View GitHub Profile
let greetings = ["hi";"hello";]
let names = ["john";"micah";]
// trying to end up with ["hi john";"hi micah";"hello john"; "hello micah;"]
// cant use zip-- real life items arent same size
greetings
|> List.fold (fun(accum,greet) -> names |> List.map (fun (name)-> greet +" "+ name) |> List.append accum ) List.empty<string>;;
@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 / 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 / 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 / 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 / hogan-express-app.js
Created December 23, 2011 21:29
Example node.js app using hogan.js and express.js
var express=require('express'),
hogan=require('hogan.js'),
adapter=require('./hogan-express.js'),
app = express.createServer();
app.configure(function(){
app.use(express.static(__dirname + '/public'));
app.use(express.logger());
app.use(express.bodyParser());
app.use(express.cookieParser());
@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};
@micahasmith
micahasmith / product-list.js
Created December 29, 2011 00:39
multiply all items in an array
var product=function(list) {
var len=list.length,
sum=1,
i=0;
for(;i<len;i+=1) {
sum=sum*list[i];
}
return sum;
}