Skip to content

Instantly share code, notes, and snippets.

View EdgeCaseBerg's full-sized avatar
📉
Wondering why Github added statuses instead of something useful

Ethan Eldridge EdgeCaseBerg

📉
Wondering why Github added statuses instead of something useful
View GitHub Profile
@davegurnell
davegurnell / anorm.scala
Last active August 14, 2023 16:42
A short guide to Anorm
/*
Overview
--------
To run a query using anorm you need to do three things:
1. Connect to the database (with or without a transaction)
2. Create an instance of `anorm.SqlQuery` using the `SQL` string interpolator
3. Call one of the methods on `SqlQuery` to actually run the query
@seratch
seratch / build.sbt
Created March 8, 2012 03:06
Using Anorm 2.0 without Play Framework
scalaVersion := "2.9.1"
resolvers += "typesafe" at "http://repo.typesafe.com/typesafe/releases"
libraryDependencies ++= Seq(
"play" %% "anorm" % "2.0-RC4",
"com.github.seratch" %% "scalikejdbc" % "[0.5,)",
"org.hsqldb" % "hsqldb" % "[2,)"
)
@lukas-vlcek
lukas-vlcek / gist:5143799
Last active February 7, 2023 21:50
Adding a new analyzer into existing index in Elasticsearch (requires close/open the index). Tested with Elasticsearch 0.19.12.
// create an index with an analyzer "myindex"
curl -X PUT localhost:9200/myindex -d '
{
"settings" : {`
"index":{
"number_of_replicas":0,
"number_of_shards":1,
"analysis":{
"analyzer":{
"first":{
#! /usr/bin/env python
import fileinput
import argparse
from operator import itemgetter
parser = argparse.ArgumentParser()
parser.add_argument('--target-mb', action = 'store', dest = 'target_mb', default = 61000, type = int)
parser.add_argument('vmtouch_output_file', action = 'store', nargs = '+')
args = parser.parse_args()
@jroper
jroper / MyManagedResource.scala
Last active November 4, 2021 10:20
Play resource routing
class MyManagedResource extends ResourceController[String] {
def index = Action(Ok("index"))
def newScreen = Action(Ok("new"))
def create = Action {
Redirect(MyInjectableResource.reverseRoutes.index())
}
def show(id: String) = Action(Ok("Show " + id))
@rrodseth
rrodseth / UnfoldPages.scala
Last active June 14, 2021 18:36
Create akka-stream Source from a pagination, using Source.unfoldAsync
// Inspired by a tweet from @trautonen 1/13/2016
// Use Source.unfoldAsync to turn paginated database results into an akka-streams Source
// unfold is the inverse of fold
case class Page[T](pageNumber:Long, totalPages:Long, contents:List[T])
case class Thing(id: Long, name: String = "foo")
val totalPages = 5 //
val pageSize = 3
@mahata
mahata / random.scala
Last active June 5, 2021 20:38
random ascii string generator in Scala
object randomSample {
def randomString(length: Int) = Stream.continually(util.Random.nextPrintableChar) take length mkString
}
println(randomSample.randomString(64))
@ian-kent
ian-kent / Authentication.scala
Created February 11, 2014 19:10
Akka based authentication and authorisation for Play Framework
package wrappers
import play.api._
import play.api.mvc._
import scala.concurrent._
import scala.concurrent.Future
import play.mvc.Http.Status
import ExecutionContext.Implicits.global
import play.libs.Akka
import akka.actor.{Actor, Props}
@julienrf
julienrf / Action.scala
Created April 9, 2012 16:20
How to implement a custom PathBindable with Play 2
def show(article: Article) = Action {
Ok(views.html.article(article))
}
@jcyamo
jcyamo / i3-exit
Last active October 9, 2020 10:26
Exit script for the i3 window manager based off of exit script from CrunchBang Linux.
#!/usr/bin/env python
# based on cb-exit used in CrunchBang Linux <http://crunchbanglinux.org/>
import pygtk
pygtk.require('2.0')
import gtk
import os
import getpass