Skip to content

Instantly share code, notes, and snippets.

@gruber
gruber / Liberal Regex Pattern for All URLs
Last active May 29, 2024 00:03
Liberal, Accurate Regex Pattern for Matching All URLs
The regex patterns in this gist are intended to match any URLs,
including "mailto:foo@example.com", "x-whatever://foo", etc. For a
pattern that attempts only to match web URLs (http, https), see:
https://gist.github.com/gruber/8891611
# Single-line version of pattern:
(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))
// Use with a default value as in:
// runningScalaVersion getOrElse "2.8.0"
lazy val runningScalaVersion = {
val matcher = """version (\d+\.\d+\.\d+).*""".r
util.Properties.versionString match {
case matcher(vsn) => Some(vsn)
case _ => None
}
}
@tolitius
tolitius / src.multi-method.clj
Created January 29, 2012 07:04
clojure bootcamp: "defmulti" example
;; inspired by suggestion in THE doc: http://java.ociweb.com/mark/clojure/article.html
(ns bootcamp.multi-method)
(defn measure-it [size]
(cond
(< size 3) :small
(< size 6) :medium
(< size 12) :large
:else :hard-to-measure ))
@tavisrudd
tavisrudd / links.txt
Created March 23, 2013 04:55
some links related to my voice coding talk at #pycon
@davepape
davepape / LeapPyglet-udp.py
Last active December 9, 2021 21:19
Pyglet program to receive hand & finger data from the hacked "LeapSample.py" program (via UDP) and render it in 2D
#
# Receive hand & finger data from "LeapSample.py" via UDP and render it in 2D
#
from pyglet.gl import *
# Create a UDP socket to receive the data
import socket
insock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Listen to port 5000
insock.bind(('',5000))
@jessitron
jessitron / stayingDead.scala
Created March 19, 2014 15:23
Akka testing: it's a good idea to tell your actor system to leave a dead top-level actor dead. See: http://blog.jessitron.com/2014/03/testing-in-akka-sneaky-automatic.html
// In real life, it's great that stuff gets restarted when it fails.
// In testing, we'd rather know that it failed.
import akka.actor._
class DyingActor extends Actor {
def receive = { case "die" => throw new Exception("poo") }
}
// Default config, everything restarts automatically
val system = ActorSystem("ordinary")
@agemooij
agemooij / 1. README.md
Last active September 26, 2018 13:19
Quick spray-routing authentication example

Extremely bare example of Spray routing authentication using session cookies and XSRF tokens

This code was quickly ripped out of an active project to serve as an example. It will not compile in any way!

Any questions? Add them to the comments!

Notes

  • the application uses a version of the cake pattern to compose the Spray routing application together from various traits
  • a lot of those traits should be pretty self-explaining based on their name but if requested I can paste them into this Gist
@guizmaii
guizmaii / GithubHelper.scala
Last active February 18, 2017 00:03
Helper object that help to parse the "Link" header of the Github API v3, in Scala
object GithubHelper {
/**
* Parse the Github Link HTTP header used for pagination
*
* http://developer.github.com/v3/#pagination
*
* Original code found here : https://gist.github.com/niallo/3109252
*
* @param linkHeader
@xuwei-k
xuwei-k / jol-example
Last active April 9, 2016 12:13
jol sample
$ screpl org.openjdk.jol%jol-core%0.2
[info] Loading global plugins from /Users/user/.sbt/0.13/plugins
[info] Set current project to ivy-console (in build file:/Users/user/.sbt/boot/ivy-console/)
Welcome to Scala version 2.11.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_25).
Type in expressions to have them evaluated.
Type :help for more information.
scala> println(org.openjdk.jol.info.ClassLayout.parseClass(classOf[Vector[Int]]).toPrintable)
scala.collection.immutable.Vector object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
@markrendle
markrendle / explanation.md
Last active July 3, 2022 07:56
Why I was previously not a fan of Apache Kafka

Update, September 2016

OK, you can pretty much ignore what I wrote below this update, because it doesn't really apply anymore.

I wrote this over a year ago, and at the time I had spent a couple of weeks trying to get Kafka 0.8 working with .NET and then Node.js with much frustration and very little success. I was rather angry. It keeps getting linked, though, and just popped up on Hacker News, so here's sort of an update, although I haven't used Kafka at all this year so I don't really have any new information.

In the end, we managed to get things working with a Node.js client, although we continued to have problems, both with our code and with managing a Kafka/Zookeeper cluster generally. What made it worse was that I did not then, and do not now, believe that Kafka was the correct solution for that particular problem at that particular company. What they were trying to achieve could have been done more simply with any number of other messaging systems, with a subscriber reading messages off and writing