Skip to content

Instantly share code, notes, and snippets.

View scravy's full-sized avatar

Julian Bertram scravy

View GitHub Profile
import java.util.concurrent.Executors
import scala.concurrent.{ExecutionContext, Future}
object Main extends App {
val executorService = Executors.newFixedThreadPool(5)
implicit val executionContext: ExecutionContext = ExecutionContext.fromExecutorService(executorService)
{-# LANGUAGE Haskell2010
, FlexibleContexts
#-}
{-# OPTIONS -Wall #-}
module Main where
import Control.Monad
import Control.Monad.ST
import Data.List
@scravy
scravy / minmax.java
Created November 13, 2013 03:08
minmax
package aufgabe1;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.concurrent.Callable;
public class MinMax<T extends Comparable<T>> {
package com.simplaex.gist
import java.util.Objects
object ToString {
trait Formattable {
override def toString: String = {
val sb = new StringBuilder
for (field <- getClass.getDeclaredFields if !field.isSynthetic) {
@scravy
scravy / insanity.md
Created December 11, 2018 20:02
Sanity and Insanity in different programming languages

Java:

class Person {
    private String firstName;
    private String lastName;
      
    public String getDisplayName() {
        return firstName + " " + lastName;
    }
@scravy
scravy / go-haskell-drugs.md
Last active January 24, 2019 22:55
golang and haskell

<dev one> [7:20 PM]

yes!

go code immediately injects into the brain, no need to even read it 🙂

what a lovely language

[7:20 PM]

# tested on macOS, required GNU Parallel (`brew install parallel`)
src/test/test_unite --list_content 2>&1 | \
grep -v -F ' ' | \
awk '{ print "src/test/test_unite --run_test=" $0 " > /dev/null 2>&1 && echo - [x] " $0 " || echo - [ ] " $0 }' | \
parallel -j 0 bash -c 2> /dev/null | \
sort
### Keybase proof
I hereby claim:
* I am scravy on github.
* I am scravy (https://keybase.io/scravy) on keybase.
* I have a public key ASDeIpZp4Noqd8mYAEpKe4FGE0opfrjJK1SoWGZsGE_xrAo
To claim this, I am signing this object:
@scravy
scravy / nicify.hs
Created September 6, 2019 11:51
A Haskell Script to nicify all kinds of structured output
import Data.List (replicate)
main = getContents >>= (\x -> putStr (proc 0 x))
space = ' '
newline = '\n'
isOpening = \c -> case c of
'[' -> True
'{' -> True

The C++ Core Guidelines recommend using lambda initialization for complex initialization: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-lambda-init

It gives the following reason:

Reason It nicely encapsulates local initialization, including cleaning up scratch variables needed only for the initialization, without needing to create a needless nonlocal yet nonreusable function. It also works for variables that should be const but only after some initialization work.

These examples use GCC 9.1 on x86-64 using -O2.