Skip to content

Instantly share code, notes, and snippets.

@mhart
mhart / index.coffee
Last active January 2, 2016 13:49
Simple example using CoffeeScript syntax with React (run with `coffee` command to verify output). Could get some nicer syntax by wrapping some of the `DOM` functions so that the first arg doesn't need to be `null` when there are no attributes - and also so that arrays could be splatted automatically for children if required.
React = require 'react'
{ul, li, div, h3, button, form, input} = React.DOM
TodoApp = React.createClass
getInitialState: ->
items: @props.items
text: ''
@mhart
mhart / gist:6302172
Last active December 21, 2015 11:58
Running `npm outdated -g` shows everything outdated (even though it's not)
$ npm outdated -g
npm http GET https://registry.npmjs.org/c-pm
npm http GET https://registry.npmjs.org/bugger
npm http GET https://registry.npmjs.org/buffet
npm http GET https://registry.npmjs.org/coffee-script
npm http GET https://registry.npmjs.org/froth
npm http GET https://registry.npmjs.org/ecstatic
npm http GET https://registry.npmjs.org/gh
npm http GET https://registry.npmjs.org/jshint
npm http GET https://registry.npmjs.org/express
var fs = require('fs'),
Trunc = require('truncating-stream'),
truncStream = new Trunc({limit: 10}),
readStream = fs.createReadStream('/dev/random')
readStream.on('end', function() { console.log('readStream ended') })
readStream.on('close', function() { console.log('readStream closed') })
readStream.pipe(truncStream).pipe(process.stdout)
@mhart
mhart / build-nprof.sh
Last active December 14, 2015 15:19
Create nprof executable based on current node version
(curl https://raw.github.com/bnoordhuis/node-profiler/master/tools/nprof-stub.js; \
for file in splaytree codemap csvparser consarray profile profile_view logreader tickprocessor tickprocessor-driver; \
do curl https://raw.github.com/joyent/node/$(node --version)/deps/v8/tools/$file.js; \
done) > nprof && chmod +x nprof
@mhart
mhart / git-fixup.sh
Created December 11, 2012 04:16
Script to fixup/squash commits given on a cmd line - can be used as a Custom Action in SourceTree
#!/bin/bash
lastCommit=""
editorCmd="sed -i ''"
for commit in $@; do
lastCommit=${commit:0:7}
editorCmd="$editorCmd -e 's/pick ${lastCommit}/fixup ${lastCommit}/'"
done
GIT_SEQUENCE_EDITOR=$editorCmd git rebase -i ${lastCommit}~2
@mhart
mhart / stream_or_die_songs.markdown
Created July 6, 2012 08:52
stream or die songs


    ____
   / /\ \
  | |
   \_\_   tt   rr rr  eee   aaaa   mmmmm
     \ \ ttttt rrrr  ee ee aa aa   mm m m
   __/ /  tt   rr    eee   a   a   mm m m
 |___/ tt rr eeee aaaaa mm m m
@mhart
mhart / test1.js
Created May 3, 2012 13:34
stdin/stdout pipe in node.js
// So this is short and easier
process.stdin.resume()
process.stdin.on('data', function(data) { process.stdout.write(data) })
process.stdout.on('error', function(err) {
if (err.code === 'EPIPE') return process.exit()
process.emit('error', err)
})
@mhart
mhart / gist:1464358
Created December 12, 2011 02:22
QueryOverStub
public class QueryOverStub<TRoot, TSub> : IQueryOver<TRoot, TSub>
{
private readonly TRoot _singleOrDefault;
private readonly IList<TRoot> _list;
private readonly ICriteria _root = MockRepository.GenerateStub<ICriteria>();
public QueryOverStub(IList<TRoot> list)
{
_list = list;
}
@mhart
mhart / gist:1226067
Created September 19, 2011 06:47 — forked from SamSaffron/gist:1225723
multi map
cnn.QueryMultiple<Table<Order>,Table<OrderLine>,Order>(
@"select * from Orders
select * from OrderLine", (orders, lines) =>
{
var map = lines.ToDictionary(line => line.OrderId);
foreach(var order in orders)
{
order.Lines = map[order.Id];
yield return order;
}