Skip to content

Instantly share code, notes, and snippets.

Avatar

Mark Volkmann mvolkmann

View GitHub Profile
@mvolkmann
mvolkmann / gist:1223437
Created Sep 17, 2011
CoffeeScript indentation
View gist:1223437
a = b = c = 0
# This works.
# Note how the 2nd line is indented so "b" in 2nd line
# is in the same column as "a" in 1st line.
if a is b and
b is c
console.log 'works'
# This also works, but is ugly.
@mvolkmann
mvolkmann / pong.js
Created May 17, 2012
RabbitMQ client code
View pong.js
var amqp = require('amqp');
var count = 3;
var exchangeName = 'apto';
var pubQueue = 'pong-queue';
var subQueue = 'ping-queue';
var connOptions = {
host: 'localhost',
port: 5672,
View form.html
<html>
<head>
<title>Test Form</title>
<script src="form.js"></script>
</head>
<body>
<form id="myform" method="post" action="http://localhost:3000">
<label for="name">Name:</label>
<input id="name" name="name" type="text"/>
<button type="submit">Go!</button>
@mvolkmann
mvolkmann / foo.js
Created Apr 12, 2013
An example of how I would write code to read from a new Node.js stream ...
View foo.js
stream.on('readable', function () {
var data;
while (true) {
data = stream.read();
if (data === null) break;
// use the data
}
});
stream.on('end', function () {
@mvolkmann
mvolkmann / math.js
Created Jan 6, 2017
CommonJS Flow example
View math.js
// @flow
function product(a, b) {
return a * b;
}
exports.product = product;
@mvolkmann
mvolkmann / demo.js
Last active May 11, 2017
Flow .js.flow declaration files
View demo.js
const double = require('./math').double;
console.log(double('20'));
@mvolkmann
mvolkmann / matt-follett.js
Created May 18, 2017
Flow type discriminating
View matt-follett.js
// @flow
type Action1Type = {
type: 'A1',
payload: {
name: string
}
};
type Action2Type = {
View demo.hs
instance LogType (IO a) where
logn' arr = do
-- Call putStr on all the elements in arr.
mapM_ putStr arr -- functions that end in _ ignore their result
-- Output a newline.
putStrLn ""
-- The "do" block must return something.
return undefined
instance (Show a, LogType r) => LogType (a -> r) where
@mvolkmann
mvolkmann / type-classes.hs
Created Feb 22, 2018
learning about Haskell type classes
View type-classes.hs
import qualified Data.Map as Map
-- A tuple of three Ints
type RGB = (Int, Int, Int)
-- Colors can be specified in three ways.
data Color =
ColorName String |
ColorHex String |
ColorRgb Int Int Int
@mvolkmann
mvolkmann / type-classes.js
Created Feb 22, 2018
JavaScript version of what I'm trying to do in Haskell
View type-classes.js
const colorNameToHexMap = {
red: 'FF0000',
green: '00FF00',
blue: '0000FF'
};
const colorHexToNameMap = {
FF0000: 'red',
'00FF00': 'green',
'0000FF': 'blue'