Skip to content

Instantly share code, notes, and snippets.

@justinholmes
justinholmes / gist:1524914
Created December 27, 2011 19:38
Play2.0 Facebook Login
object Application extends Controller {
val FBAppId = "AppIdGoesHere"
val FBAppSecret = "FBAppSecretGoesHere"
def fbLogin = Action {Redirect("https://www.facebook.com/dialog/oauth?scope=user_birthday,email,user_about_me,user_location,offline_access,publish_stream,user_education_history,user_checkins" +
"&client_id="+FBAppId+"&redirect_uri="+URLEncoder.encode("http://domainname.com/fbLogin/code","UTF-8"))}
def fbLoginCode(code:String) = Action{response =>
val ws = WS.url("https://graph.facebook.com/oauth/access_token?client_id="+FBAppId+"&redirect_uri" +
@justinholmes
justinholmes / Controller.scala
Created January 7, 2012 22:11 — forked from bwmcadams/Controller.scala
Play 2.0 Scala + MongoDB via Salat
package controllers
import play.api._
import play.api.mvc._
import com.novus.salat._
import com.novus.salat.global._
import com.novus.salat.dao._
import util._
@justinholmes
justinholmes / finagle.scala
Created February 12, 2012 02:14
finagle reverse proxy - do not use in production
package com.nascency.incipit
import com.twitter.finagle.{Service, SimpleFilter}
import org.jboss.netty.handler.codec.http._
import org.jboss.netty.handler.codec.http.HttpResponseStatus._
import org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1
import org.jboss.netty.buffer.ChannelBuffers.copiedBuffer
import org.jboss.netty.util.CharsetUtil.UTF_8
import com.twitter.util.Future
import java.net.InetSocketAddress
@justinholmes
justinholmes / githook.sh
Created June 5, 2012 21:00
Git hook for PlayFramework 2.0 apps to deploy to a remote server
#!/bin/sh
#
# An example hook script that is called after a successful
# commit is made.
#
# To enable this hook, rename this file to "post-commit".
path="path to application"
User="userforssh"
server="servername"
dist="/Users/justin/Apps/Play20/play dist"
@justinholmes
justinholmes / deploy.sh
Created June 5, 2012 21:01
Deployment script on remote server
#!/bin/bash
unzip -o filename-1.0
chmod a+x filename-1.0/start
gline=$(ps -ewwo pid,args | grep "play.core.server.NettyServer")
echo $gline
IN=$gline
set -- "$IN"
IFS=" "; declare -a Array=($*)
PlayProcess="$(ps -ewwo pid,args | grep "play.core.server.NettyServer")"
echo $PlayProcess
@justinholmes
justinholmes / disruptor.scala
Created September 21, 2012 21:19
Scala disruptor trade example into MongoDB and Project Voldemort
import com.lmax.disruptor.dsl.Disruptor
import java.util.concurrent.Executors
import com.lmax.disruptor._
import com.mongodb.casbah.Imports._
import voldemort.client._
object Main {
val bootstrapUrl = "tcp://localhost:6666"
val factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
val client = factory.getStoreClient[String, String]("test");
@justinholmes
justinholmes / gatling.scala
Created November 21, 2012 15:15
Gatling And Play!
package controllers
import play.api._
import play.api.mvc._
import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._
import com.excilys.ebi.gatling.jdbc.Predef._
import com.excilys.ebi.gatling.core.result.message.RunRecord
import com.excilys.ebi.gatling.charts.report.ReportsGenerator
import com.excilys.ebi.gatling.core.runner.{Selection, Runner}
sudo du -h | grep "[\0-9\]G"
find -name *.war -exec scp '{}' [email protected]:webapps ';'
find -name *.jmx -exec sh ${JENKINS_HOME}/jmeter/bin/jmeter -n -t {} -l ${WORKSPACE}/{}.jtl ';'
awk '/MemTotal:/{total=$2} \
/MemFree:/{free=$2} \
END{ \
print "free:"(free*100/total)",";
# Documentation for HAProxy
# http://code.google.com/p/haproxy-docs/w/list
# http://haproxy.1wt.eu/download/1.2/doc/architecture.txt
# NOTES:
# open files limits need to be > 256000, use ulimit -n to set (on most POSIX systems)
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
@justinholmes
justinholmes / haproxy-marathonv2.sh
Last active September 9, 2019 01:01
Haproxy config generator using Marathon
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
require 'net/http'
url = URI.parse("http://marathon.apps.company.com/v2/tasks")
req = Net::HTTP::Get.new(url.path)
req.add_field("Accept", "application/json")
res = Net::HTTP.new(url.host, url.port).start do |http|
http.request(req)