Skip to content

Instantly share code, notes, and snippets.

View keirlawson's full-sized avatar

Keir Lawson keirlawson

View GitHub Profile
@keirlawson
keirlawson / generate.scala
Created March 25, 2022 22:24
JSON test file from Scalacheck Arbitrary/Circe Encoder
def streamGen[A](gen: Gen[A]): Stream[IO, A] = Stream.repeatEval(IO(gen.sample)).flatMap(Stream.fromOption(_))
def generateTestFile[A : Arbitrary : Encoder](file: fs2.io.file.Path, items: Long): IO[Unit] = {
val values = streamGen(Arbitrary.arbitrary[A])
val jsons = values.map(Encoder[A].apply).take(items)
val lines = Stream("[\n") ++ jsons.map(_.toString()).intersperse(",\n") ++ Stream("]")
lines
.through(text.utf8.encode)
.through(Files[IO].writeAll(file))
@keirlawson
keirlawson / cargo.toml
Created October 23, 2019 22:10
Deserialise unit as emtpy list
[package]
name = "desertest"
version = "0.1.0"
authors = ["Keir Lawson <[email protected]>"]
edition = "2018"
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.8"
package com.example.websocketdownload
import cats.effect.IO
import me.tongfei.progressbar.{ProgressBar => pBar}
import fs2.{Sink, Stream}
import cats.implicits._
class ProgressBar(value: pBar) {
def start(): IO[Unit] = IO {
case class BigString(value: String) extends AnyVal
def getClob(rs: ResultSet, i: Int): BigString = {
val clob = rs.getClob(i)
val str = Source.fromInputStream(clob.getAsciiStream).mkString
BigString(str)
}
def setClob(ps: PreparedStatement, i: Int, bs: BigString): Unit = {
val reader = new StringReader(bs.value)
module.exports = {
config: {
// default font size in pixels for all tabs
fontSize: 14,
// font family with optional fallbacks
fontFamily: 'Menlo, "DejaVu Sans Mono", Consolas, "Lucida Console", monospace',
// terminal cursor background color and opacity (hex, rgb, hsl, hsv, hwb or cmyk)
cursorColor: 'rgba(248,28,229,0.8)',
@keirlawson
keirlawson / installkeyringhelper.sh
Created February 21, 2016 10:36
Install gnome-keyring git credential helper in Ubuntu
sudo apt-get install libgnome-keyring-dev
cd /usr/share/doc/git/contrib/credential/gnome-keyring
sudo make
sudo ln -s /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring /usr/lib/git-core/
@keirlawson
keirlawson / gulpfile.js
Last active January 19, 2016 20:16
Demonstrating bug in karma-jsdom-launcher 2.0.0
var gulp = require('gulp');
var Server = require('karma').Server;
gulp.task('test', function (done) {
new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done).start();
});