Skip to content

Instantly share code, notes, and snippets.

View marcinwyszynski's full-sized avatar

Marcin Wyszynski marcinwyszynski

View GitHub Profile
@marcinwyszynski
marcinwyszynski / apple1.rb
Last active September 19, 2016 14:01
Clever duplication trick
# frozen_string_literal: true
class Apple
def one
loop do
'kaboom'
.map { |char| char.upcase.downacase }
.filter { |char| char != '0' }
.drop { |char| char == 7 }
end
end
package main
import (
"fmt"
"net"
"net/http"
"strconv"
"strings"
"time"
FROM ruby:2.2.3
ENV APP_HOME=/consumer
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
COPY Gemfile* $APP_HOME/
RUN bundle install
package main
import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
#!/usr/bin/env python
import sys
def parse_arglist(args):
arglist = []
for arg in args:
if not arg.startswith('-'):
arglist.append(arg)
import os
import time
def open_unless_older_than(age_s, path):
meta = os.stat(path) # will throw IOError if path does not exist
if time.time() - meta.st_mtime > age_s:
raise IOError('File older than %d seconds' % age_s)
return open(path, r)
@marcinwyszynski
marcinwyszynski / wagnerfisher.go
Created July 29, 2014 21:42
Wagner-Fisher algorithm to calculate edit distance of two strings
// Wagner–Fischer a dynamic programming algorithm that computes the edit distance between
// two strings of characters.
//
// Source:
// http://en.wikipedia.org/wiki/Wagner%E2%80%93Fischer_algorithm
package main
import (
"fmt"
)
@marcinwyszynski
marcinwyszynski / chunked_reader.go
Created April 23, 2014 14:21
ChunkedReader is an io.Reader which runs a callback after each read chunk
package chunked_reader
import "io"
// ChunkedReader implements io.Reader interface while allowing the source to be
// read in set increments and running a callback function after each increment.
type ChunkedReader struct {
readSoFar int64
Reader io.Reader // The underlying io.Reader.
ChunkSize int // Maximum bytes to read on each Read call.
@marcinwyszynski
marcinwyszynski / trie.go
Last active August 29, 2015 13:57
Generic Trie for storing bytes
package trie
const (
// Number of possible values represented by a single byte.
byteValues = 1 << 8
)
type Trie struct {
culDeSac bool
children []*Trie
@marcinwyszynski
marcinwyszynski / selfref.go
Created March 6, 2014 00:12
Golang: self-referential functions
// Original idea:
// http://commandcenter.blogspot.nl/2014/01/self-referential-functions-and-design.html
package main
import "fmt"
type Cat struct {
Name string
}