Skip to content

Instantly share code, notes, and snippets.

@fwgreen
fwgreen / ViewAgg.sql
Last active June 22, 2019 05:55
PostgreSQL view wth aggregation functions
drop view if exists normal.contact_information;
create or replace view normal.contact_information as
select normal.person.first_name || ' ' || normal.person.last_name as full_name,
normal.person.id as person_id,
array_agg(distinct normal.email.address) as emails,
array_agg(distinct normal.telephone.number) as telephones,
row_number() over () as id
from normal.person, normal.email, normal.telephone
where
@fwgreen
fwgreen / RegexRedux.java
Last active March 26, 2022 23:33
Java 10 implementation of Regex Redux
import java.io.*;
import java.util.concurrent.CompletableFuture;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.*;
public class RegexRedux {
@fwgreen
fwgreen / regex_redux.rs
Created August 1, 2017 05:43
Rust implementation of the Benchmark Game's Regex Redux challenge
extern crate regex;
use std::io::{self, Read};
use std::thread;
macro_rules! regex { ($re:expr) => { ::regex::bytes::Regex::new($re).unwrap() } }
fn main() {
let mut input = Vec::with_capacity(51 * (1 << 20));
@fwgreen
fwgreen / RegexRedux.swift
Created June 27, 2017 17:35
Swift 3.1 implementation of Regex-Redux
import Foundation
import Dispatch
let input = FileHandle.standardInput.readDataToEndOfFile()
var sequence = String(data: input, encoding: .utf8)!
let inputLength = input.count
let regex: (String) -> NSRegularExpression = { pattern in
@fwgreen
fwgreen / RegexReduxWrong.java
Last active September 24, 2020 07:09
Incorrect Java 10 implementation of RegexRedux
import java.io.*;
import java.util.concurrent.CompletableFuture;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.*;
public class RegexRedux {
public static void main(String[] args) {
@fwgreen
fwgreen / RegexRedux.ceylon
Created March 21, 2017 19:46
A Ceylon attempt at the [Benchmarks Game](http://benchmarksgame.alioth.debian.org/) RegexRedux challenge
import ceylon.file {
...
}
import ceylon.regex {
...
}
import java.util.concurrent {
CompletableFuture { supplyAsync }
}
import ceylon.net.uri { parseURI=parse,... }
import ceylon.json { parseJSON=parse,... }
shared void run() {
value base = "http://api.icndb.com/jokes/random?";
value params = { "limitTo"->"[nerdy]", "firstName"->"Francois", "lastName"->"Green" };
value query = params.map((e) => "``e.key``=``e.item``").interpose("&").reduce(plus);
value contents = parseURI(base+query).get().execute().contents;
value json = parseJSON(contents);
@fwgreen
fwgreen / BookService.ceylon
Last active February 21, 2016 20:10
RESTful service made with gyokuro: https://github.com/bjansen/gyokuro
import com.github.bjansen.gyokuro { ... }
import ceylon.net.http.server { ... }
import ceylon.net.http { Header }
import ceylon.collection { ... }
import ceylon.math.float { ... }
class Book(author, title) {
shared variable String author;
shared variable String title;
string => "Author: ``author`` Title: ``title``";
@fwgreen
fwgreen / BookList.ceylon
Last active February 21, 2016 20:12
Simple web app using gyokuro: https://github.com/bjansen/gyokuro
import com.github.bjansen.gyokuro { ... }
import ceylon.net.http.server { ... }
import ceylon.html { ... }
import ceylon.collection { ... }
import ceylon.math.float { ... }
class Book(author, title) {
shared variable String author;
shared variable String title;
string => "Title: ``title`` \nAuthor: ``author``";