Skip to content

Instantly share code, notes, and snippets.

@williamho
williamho / README.md
Last active June 29, 2018 15:02
hyperapp setup
yarn install
yarn parcel
@williamho
williamho / build.sbt
Created August 29, 2017 16:26
Temporarily change an sbt setting and execute task
val greet = taskKey[Unit]("Says hello to you")
// Reverses the value of `name` and calls `greet`
val greetReverse = Command.command("greetReverse") { state =>
val extracted = Project.extract(state)
val newState = extracted.append(Seq(name := name.value.reverse), state)
Project.runTask(greet, newState)
@williamho
williamho / github_graphql.txt
Created June 9, 2017 21:25
Get open pull requests in repos with topic by user
{
search(query: "user:insert_user_here topic:insert_topic_here", type: REPOSITORY, first: 50) {
nodes {
... on Repository {
name
pullRequests(states: OPEN, orderBy: {field: CREATED_AT, direction: DESC}, first: 10) {
nodes {
title
author {
avatarUrl
@williamho
williamho / mediatags.html
Last active February 15, 2017 02:40
Frontend JS to extract title/artist from audio files
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Song metadata</title>
</head>
<body>
<script src="https://rawgit.com/aadsm/jsmediatags/master/dist/jsmediatags.min.js"></script>
@williamho
williamho / hardwrap.js
Created December 15, 2016 16:08
hard wrap selected textarea to 72 columns
(function() {
function wrap(s, maxLength) {
return s.split(' ').reduce(function(acc, x) {
var i = acc.length - 1;
var last = acc[i] == '' ? x : (acc[i] + ' ' + x);
if (last.length > maxLength) {
acc.push(x);
} else {
acc[i] = last;
@williamho
williamho / leaflet.html
Created October 10, 2016 03:59
leaflet map
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
body, #map {
width: 100%;
height: 100%;
import shapeless._
import shapeless.labelled._
import shapeless.ops.function._
import shapeless.ops.hlist._
import shapeless.ops.record._
import shapeless.record._
import shapeless.syntax.singleton._
import shapeless.syntax.std._
import shapeless.syntax.std.function._
import shapeless.syntax.std.traversable._
@williamho
williamho / scalameta.md
Last active May 12, 2016 13:55
Demo from scaladays

scala.meta

scala> import scala.meta._
import scala.meta._

scala> val res2 = "foo + bar".parse[Term]
res2: scala.meta.parsers.Parsed[scala.meta.Term] = foo + bar

scala> val res3 = res2.get
scala> import org.joda.time._
import org.joda.time._
scala> val j = Json.obj("date" -> "2012-08-16 17:52:20")
j: play.api.libs.json.JsObject = {"date":"2012-08-16 17:52:20"}
scala> implicit val dateReads = Reads.jodaDateReads("yyyy-MM-dd HH:mm:ss")
dateReads: play.api.libs.json.Reads[org.joda.time.DateTime] = play.api.libs.json.DefaultReads$$anon$22@3e886411
scala> (j \ "date").as[DateTime]
@williamho
williamho / FindClass.sbt
Last active April 9, 2016 21:49
sbt task to find class in classpath matching a specified name
lazy val allClasses = taskKey[Stream[String]]("Classes in classpath")
lazy val findClass = inputKey[Stream[String]]("Find classes matching name")
findClass := {
import complete.DefaultParsers._
val any = ".*"
val parts: Seq[String] = spaceDelimited("<arg>").parsed
val caseSensitive: Boolean = parts.exists(_.matches(s"$any[A-Z]$any"))
val regex: String = (if (caseSensitive) "" else "(?i)") +