View cabal.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with builtins; rec { | |
cabalProjects = listToAttrs (if pathExists ./cabal.project | |
then projectParse | |
else [ { name = baseNameOf ./.; value = ./.; } ] ); | |
projectParse = let | |
contents = readFile ./cabal.project; | |
trimmed = replaceStrings ["packages:" " "] ["" ""] contents; | |
packages = filter (x: isString x && x != "") (split "\n" trimmed); | |
package = p: substring 0 (stringLength p - 1) p; | |
paths = map (p: let p' = package p; in { name = p'; value = toPath (./. + "/${p'}"); } ) packages; |
View JdbcStreams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public <T> T streamQuery(String sql, Function<Stream<SqlRowSet>, ? extends T> streamer, Object... args) { | |
return jdbcTemplate.query(sql, resultSet -> { | |
final SqlRowSet rowSet = new ResultSetWrappingSqlRowSet(resultSet); | |
final boolean parallel = false; | |
// The ResultSet API has a slight impedance mismatch with Iterators, so this conditional | |
// simply returns an empty iterator if there are no results | |
if (!rowSet.next()) { | |
return streamer.apply(StreamSupport.stream(Spliterators.emptySpliterator(), parallel)); | |
} |
View cabal.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ basePath ? ./.}: | |
with builtins; rec { | |
cabalProjects = listToAttrs (if pathExists (basePath + "/cabal.project") | |
then projectParse | |
else [ { name = baseNameOf basePath; value = basePath; } ] ); | |
projectParse = let | |
contents = readFile (basePath + "/cabal.project"); | |
trimmed = replaceStrings ["packages:" " "] ["" ""] contents; | |
packages = filter (x: isString x && x != "") (split "\n" trimmed); | |
package = p: substring 0 (stringLength p - 1) p; |
View gist:8c86ccbf1f819f119d88648833613be4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <pthread.h> | |
volatile char toggle = 1; | |
void *writer(void *unused) { | |
for (;;) { | |
toggle = 1; | |
toggle = 2; |
View search_deep.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Search_Deep where | |
import Data.Bits | |
data Fun = And | Add | Xor | Or | Sub | Bus | |
data Shape = F Shape Shape | Var | Tok | |
data Expr a = C Fun (Expr a) (Expr a) | V a | T | |
data U = U | |
instance Show U where | |
showsPrec _ U = ("?" ++) |
View Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ubuntu:xenial | |
ENV DEBIAN_FRONTEND noninteractive | |
RUN rm -rf /var/lib/apt/lists/* && \ | |
apt-get update -q -q && \ | |
echo 'UTC' > /etc/timezone && \ | |
dpkg-reconfigure tzdata | |
COPY postfix_3.0.4-5ubuntu1_amd64.deb /root/ |
View proc.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/stack runghc | |
import Data.Char (toUpper) | |
import Data.List (uncons) | |
ucFirst :: String -> String | |
ucFirst = maybe "" (\(a,b) -> toUpper a : b) . uncons | |
process :: String -> [String] | |
process s = | |
let slug = mconcat $ map ucFirst $ words s |
View Foo.bytecode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo { | |
Foo(); | |
Code: | |
0: aload_0 | |
1: invokespecial #1 // Method java/lang/Object."<init>":()V | |
4: return | |
public boolean isEven(java.lang.Integer); | |
Code: | |
0: aload_1 |
View JdbcStreamsExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set<String> results = jdbcStream.streamQuery("SELECT * FROM test_data", stream -> stream | |
.map(row -> row.getString("entry")) | |
.filter(s -> Character.isAlphabetic(s.charAt(0))) | |
.collect(Collectors.toSet())); |
View ghcimport.vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
command! -buffer -nargs=0 -bang GhcModImport call Autoimport(<bang>0) | |
function! Autoimport(force) "{{{ | |
let l:identifier = ghcmod#getHaskellIdentifier() | |
let l:parts = split(l:identifier, '\.') | |
" `ghc-mod sig` is available since v5.0.0. | |
let l:cmd = ghcmod#build_command(['find', l:parts[-1]]) | |
let l:lines = split(ghcmod#system(l:cmd), '\n') | |
if len(l:lines) >= 1 | |
let l:module = l:lines[0] | |
let l:view = winsaveview() |
NewerOlder