Skip to content

Instantly share code, notes, and snippets.

abstract class LogFormatter[-A] {
def format(a: A): String
}
object LogFormatter {
implicit object StringLogFormatter extends LogFormatter[String] {
def format(s: String) = s
}
implicit object ExceptionLogFormatter extends LogFormatter[Exception] {
<script>window.location.href='http://s3.amazonaws.com/37assets/svn/461-spinner.html';</script>
@rby
rby / autoclose.scala
Created December 9, 2010 07:01
Autoclose with for comprehensions
object closable {
type Closable = { def close }
class Autoclose[A <: Closable](c: A){
def foreach(f: A => Unit) = {
try { f(c) }finally { c.close }
}
}
case class Connection(name:String) {
def close = println("closing " + this)
}
@mchampine
mchampine / pwprot.clj
Created March 13, 2011 19:13
Strong password hasher/verifier for Clojure - incorporating salt and iterations
(ns pwprot
(:import (java.security MessageDigest Security)))
;;generate n random chars
(defn gensalt [n]
(let [charseq (map char (concat
(range 48 58) ; 0-9
(range 97 123)))] ; 0-z
(apply str
(take n
@stuartstevenson
stuartstevenson / jenkins-job-dsl.groovy
Created September 16, 2014 07:50
Jenkins job dsl with distributed job config files. The seed.groovy file scans stash repo branches for jenkins-job-dsl.groovy files and runs them centrally.
Closure job = {
// Job Name
name "${stashProjectKey}-${projectName}-${branchSimpleName}"
// Where should jenkins run the job
label ('master')
// Where should Jenkins get the source code from
scm {
git {
@TheSeamau5
TheSeamau5 / EntityComponentSystemExploration.md
Created December 29, 2014 23:16
An exploration of the Entity Component System in Elm

#Exploring Entity Component Systems in Elm

Entity-Component-System (or ECS) is a pattern for designing programs that is prevalent in the games industry. This pattern consists of three simple parts:

  • Entity : A uniquely identifiable object that may contain any number of components
  • Component : A property usually representing the raw data of one aspect of the object. (Position is a component, Velocity is a component, Strength is a component, etc...)
  • System : A continuous process performing actions on every entity that possesses a component of the same aspect as that system

To understand this, let us try to make a simple example: Boxes that move in space:

@hayderimran7
hayderimran7 / get-api-token-of-user-jenkins-groovy.md
Last active June 7, 2021 14:24
jenkins groovy get API token of a user

This is pretty simple snippet to get API Token of a user , lets say "MYUser" in jenkins.
its pretty useful when you are working with 'jenkins-job-builder' to update jobs in jenkins, and you need to get the api token which JJB needs inorder to update jobs to ..
run this code in either jenkins script console , or as i prefer, in form of init.groovy.
so when jenkins master starts, i create a user for JJb.
after that i get the token right away and pass it to my JJB jobs folder to file 'jenkins_jobs.ini' :)_ .

///////////////////////////////////////////////////////////////////////
@michelsalib
michelsalib / timestampable.ts
Created April 22, 2015 15:52
Typescript @timestampable annotation
@timestampable
class Dog {
public name: string = 'Paul';
}
function timestampable(func) {
return <any>(function() {
var genericConstructor = () => {};
genericConstructor.prototype = func.prototype;
var instance = new genericConstructor();
@cyrille-leclerc
cyrille-leclerc / jenkins-pipeline.groovy
Created January 24, 2016 23:48
Jenkins Pipeline Script for maven-release-plugin
#!groovy
docker.image('cloudbees/java-build-tools:0.0.6').inside {
checkout([$class: 'GitSCM',
branches: [[name: '*/master']],
extensions: [
/* [$class: 'UserIdentity', email: 'cleclerc@cloudbees.com', name: 'Jenkins as a Service'], */
[$class: 'WipeWorkspace'],
[$class: 'LocalBranch', localBranch: 'master']],
userRemoteConfigs: [[credentialsId: 'github-credentials', url: 'https://github.com/cyrille-leclerc/my-spring-boot-app.git']]])
@mgoodness
mgoodness / k8s-svc-annotations.md
Last active March 11, 2024 16:24
AWS ELB-related annotations for Kubernetes Services (as of v1.12.0)
  • service.beta.kubernetes.io/aws-load-balancer-access-log-emit-interval (in minutes)
  • service.beta.kubernetes.io/aws-load-balancer-access-log-enabled (true|false)
  • service.beta.kubernetes.io/aws-load-balancer-access-log-s3-bucket-name
  • service.beta.kubernetes.io/aws-load-balancer-access-log-s3-bucket-prefix
  • service.beta.kubernetes.io/aws-load-balancer-additional-resource-tags (comma-separated list of key=value)
  • service.beta.kubernetes.io/aws-load-balancer-backend-protocol (http|https|ssl|tcp)
  • service.beta.kubernetes.io/aws-load-balancer-connection-draining-enabled (true|false)