View stringsim.rs
//! The stringsim program prints out the trigram similarity of two strings | |
//! using what appears to be the same algorithm used by Postgres. | |
//! https://www.postgresql.org/docs/9.1/pgtrgm.html | |
use std::collections::HashSet; | |
use std::hash::Hash; | |
fn main() { | |
let args: Vec<String> = ::std::env::args().collect(); | |
if args.len() != 1+2 { |
View gofast_issue_28.go
// This program spins up php-fpm in the background and a Go web server sending | |
// all requests to a PHP router script. | |
package main | |
import ( | |
"context" | |
"flag" | |
"fmt" | |
"io/ioutil" | |
"log" |
View mfilt
#!/usr/bin/env python | |
import argparse | |
import re | |
import sys | |
parser = argparse.ArgumentParser(description= | |
'''Filter some text with a regex, allowing matches to span multiple lines. | |
This tool is based on some ideas from Rob Pike's Sam editor: |
View sieve.clj
;; A concurrent prime sieve translated from | |
;; https://golang.org/doc/play/sieve.go | |
;; by Issac Trotts with help from Chris Murphy and glts on Stack Overflow. | |
(require '[clojure.core.async :as async :refer [<! >! <!! chan go]]) | |
(defn generate-naturals | |
"Sends the sequence 2, 3, 4, ... to channel 'ch'." | |
[ch] | |
(go |
View sieve.erl
#!/usr/bin/env escript | |
%% -*- mode: erlang -*- | |
%%! -smp enable -hidden | |
%% | |
%% A concurrent prime sieve, inspired by the Go prime sieve | |
%% with daisy-chained filter processes. | |
%% https://golang.org/doc/play/sieve.go | |
%% | |
%% Translated by Issac Trotts (2016) | |
%% with help from Amiramix on StackOverflow. |
View quine.go
package main | |
import "fmt" | |
func main() { | |
s := "package main\n\nimport \"fmt\"\n\nfunc main() {\n\ts := %#v\n\tfmt.Printf(s, s)\n}\n" | |
fmt.Printf(s, s) | |
} |
View splat.go
// See https://code.google.com/p/go/issues/detail?id=640 | |
package main | |
import "fmt" | |
func main() { | |
args := []int{1, 2, 3} | |
fmt.Println(sum(args...)) | |
} |
View focus.go
package main | |
import ( | |
"flag" | |
"fmt" | |
"github.com/elazarl/goproxy" | |
"log" | |
"net/http" | |
"os" | |
) |
View SwapElts.hs
module SwapElts where | |
-- If you have to use this function, arrays may be a better choice. | |
swapElts i j ls = [get k x | (k, x) <- zip [0..length ls - 1] ls] | |
where get k x | k == i = ls !! j | |
| k == j = ls !! i | |
| otherwise = x | |
-- This is a nice example of how to efficiently generate test cases. | |
-- A naive approach would have been to take separate arguments for |
View check_balance.hs
#!/usr/bin/env runhaskell | |
{-# LANGUAGE TemplateHaskell #-} | |
import Test.QuickCheck ((==>), Property) | |
import Test.QuickCheck.All (quickCheckAll) | |
-- main = interact $ show . checkBalance | |
main = $quickCheckAll | |
checkBalance :: String -> Bool |
NewerOlder