Skip to content

Instantly share code, notes, and snippets.

@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``";
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 / 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 }
}
@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 / 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 / AsyncRegex.kt
Created January 29, 2019 05:52
RegexRedux in Kotlin with coroutines
import kotlinx.coroutines.*
import java.io.File
fun main() = runBlocking {
val start = System.nanoTime()
val input = File("file_path.txt").readText(Charsets.UTF_8)
val sequence = ">.*\n|\n".toRegex().replace(input, "")
val replacements = listOf(
@fwgreen
fwgreen / index.html
Created February 16, 2019 03:44
Basic html5 page with stylesheet
<!DOCTYPE html>
<html>
<head>
<title>Web Page</title>
<link rel="stylesheet" href="styles.css">
<meta name="viewport" content="width=device-width">
</head>
<body>
<main>
<header>header</header>
@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 / CollectionUtils.java
Last active April 2, 2020 13:47
Collection utilities I tend to forget how to implement
<E> List<List<E>> chunk(List<E> list, int size) {
int length = list.size();
return IntStream.range(0, (length - 1) / size + 1)
.mapToObj(i -> list.subList(i *= size, length - size >= i ? i + size : length))
.collect(Collectors.toList());
}
<T, U> Map<T, U> zip(List<T> first, List<U> second) {
return IntStream.range(0, Math.min(first.size(), second.size())).boxed()
.collect(Collectors.toMap(first::get, second::get));