Skip to content

Instantly share code, notes, and snippets.

View softprops's full-sized avatar
®️
Rustling

Doug Tangren softprops

®️
Rustling
View GitHub Profile
@chrislewis
chrislewis / Foo.scala
Last active August 29, 2015 14:02
Not so sealed
sealed trait Foo
case class Bar(x: Int) extends Foo
case class Baz(name: String) extends Foo
object Foo {
def show(f: Foo) =
f match {
case Bar(x) => x.toString // Quux, a subtype of Bar in a different file, will be matched as a Bar
case Baz(name) => name
}
#!/bin/sh
function copy_if_changed {
local path_from="$2/$1"
local path_to="$3/$1"
local md5_from=$(md5 -q $path_from)
if [ -e $path_to ]
then
@AitorATuin
AitorATuin / AsyncDirective.scala
Created June 1, 2014 13:57
Jetty Async Plans with Directives Support for Unfiltered
import unfiltered.response._
import unfiltered.request._
import unfiltered.filter._
import unfiltered.directives._
import Directive._
import scala.concurrent.Future
import scala.util.Try
import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
object AsyncDirective {
@kyledrake
kyledrake / ferengi-plan.txt
Last active April 6, 2024 00:30
How to throttle the FCC to dial up modem speeds on your website using Nginx
# The blog post that started it all: https://neocities.org/blog/the-fcc-is-now-rate-limited
#
# Current known FCC address ranges:
# https://news.ycombinator.com/item?id=7716915
#
# Confirm/locate FCC IP ranges with this: http://whois.arin.net/rest/net/NET-165-135-0-0-1/pft
#
# In your nginx.conf:
location / {
@jontg
jontg / gist:9745186
Last active February 25, 2016 10:08
Zero Downtime
#!/bin/bash
# Source files so we can announce stuff
. /mnt/apps/scripts/setenv.sh
. /mnt/apps/scripts/hipchat_notify.sh
if [ $(pidof -x deploy_if_new.sh | wc -w) -gt 2 ]; then
echo "$(date +"%Y-%m-%d %H:%M:%S %Z") Cowardly exiting as deploy_if_new is already running"
exit -1
fi
@non
non / build.sbt
Last active August 29, 2015 13:57
Fun little program to display N digits of Pi in any base (2-36) using Spire.
// this is the build file used to compile piday.scala
name := "piday"
scalaVersion := "2.10.3"
libraryDependencies += "org.spire-math" %% "spire" % "0.7.3"
var attempts = 1;
function createWebSocket () {
var connection = new WebSocket();
connection.onopen = function () {
// reset the tries back to 1 since we have a new connection opened.
attempts = 1;
// ...Your app's logic...
@daggerrz
daggerrz / gist:9310425
Created March 2, 2014 17:41
GraphiteReporter
package com.tapad.common.metrics
import java.net.Socket
import java.io._
import com.tapad.common.log.Logging
import com.twitter.ostrich.stats._
import java.util.TimerTask
object GraphiteReporter {
def apply(prefix: String, host: String, port: Int, reportInterval: Long) = {
@jmhodges
jmhodges / welp.scala
Last active August 29, 2015 13:56
The catch statement doesn't print the text. Seen with scala 2.8.1, 2.9.2 and now 2.10.x.
object Welp {
def foobar(a: Int, b: Int, c:Int) { throw new IllegalArgumentException }
def main(args: Array[String]) {
List(3) map {
try {
foobar(1, 2, _)
} catch {
case e: Throwable => { // This set of braces is optional. Problem remains when removed.
println("won't be printed")
@RadoBuransky
RadoBuransky / dist-play-app-initd
Last active March 24, 2020 20:26
Init.d shell script for Play framework distributed application. Provides start, stop, restart and status commands to control applications packaged using standard "play dist" packaging command.
#!/bin/bash
#
# =========================================================================
# Copyright 2014 Rado Buransky, Dominion Marine Media
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0