Skip to content

Instantly share code, notes, and snippets.

@maiah
maiah / immutable_collection.go
Created October 2, 2015 09:03
Copy Method for Immutable slices and maps
package main
import "fmt"
type nums []int
func (n nums) copy() []int {
dest := make(nums, len(n))
copy(dest, n)
return dest
@maiah
maiah / file_upload_sample.dart
Created October 19, 2012 10:05
File Upload Sample in Dart
final List<int> data = new List<int>();
req.inputStream.onData = () {
data.addAll(req.inputStream.read());
};
req.inputStream.onClosed = () {
String dataString = new String.fromCharCodes(data);
List<String> contents = dataString.split('\n');
@maiah
maiah / test_view.js
Created November 22, 2012 04:02
Component View Sample Usage
var domify = require('domify');
var View = require('view');
var html = '<input type="text" class="name"></input>';
var Person = function(name) {
this.name = name;
};
var maiah = new Person('Maiah Macariola');
@maiah
maiah / main.go
Last active October 19, 2015 01:39
Something like Reduce, Map, and Collect in Go
package main
import (
"fmt"
"strconv"
)
type Power struct {
up int
}
@maiah
maiah / main.go
Created October 19, 2015 07:45
Streaming Reduce, Map, and Collect in Go
package main
import (
"fmt"
"strconv"
)
type Power struct {
up int
}
@maiah
maiah / main.go
Last active October 20, 2015 23:50
Reader wrapper to have functional programming style of reading io (no mutables)
package main
import (
"fmt"
"io"
"os"
)
func main() {
f, err := os.Open("./temp")
@maiah
maiah / main.go
Last active October 26, 2015 08:14
Beautiful Streaming Filter, Map, and Collect using Channel Struct-wrapper
package main
import (
"fmt"
"strconv"
)
type Power struct {
up int
}
defmodule P2 do
def num_to_list(mx) when mx > 1 do
num_to_list(mx, mx - 1)
end
def num_to_list(mx) do
"#{mx}"
end
defmodule P2 do
def num_to_list(mx) do
if mx > 1 do
Enum.reduce(1..mx, fn (x, acc) -> "#{acc},#{x}" end)
else
"#{mx}"
end
end
@maiah
maiah / pokemon.js
Last active December 10, 2015 01:22
Pokemon evolution with Javascript streams
'use strict';
const f = require('from');
const t = require('through');
const pokemons = f(['charmander', 'bulbasaur', 'squirtle']);
const evolve = t((pokemon) => {
'use strict';
let evolvedPokemon = pokemon;