Skip to content

Instantly share code, notes, and snippets.

@joseraya
joseraya / ResultSetMappers.sc
Last active January 13, 2017 23:17
Proof of concept of a ResultSet to case class mapper in scala
import java.sql.ResultSet
object ResultSetReaders {
trait Reader[T] {
def fromResultSet(column: Int, rs: ResultSet): T
}
implicit val stringReader = new Reader[String] {
override def fromResultSet(column: Int, rs: ResultSet): String = {

Keybase proof

I hereby claim:

  • I am joseraya on github.
  • I am joseraya (https://keybase.io/joseraya) on keybase.
  • I have a public key whose fingerprint is 8D00 6D27 34A0 A548 9935 24CE 84A8 77EF 4614 3D0F

To claim this, I am signing this object:

@joseraya
joseraya / CorsSupport.scala
Created July 1, 2014 21:24
CORS directive for Spray
package com.agilogy.spray.cors
import spray.http.{HttpMethods, HttpMethod, HttpResponse, AllOrigins}
import spray.http.HttpHeaders._
import spray.http.HttpMethods._
import spray.routing._
// see also https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
trait CORSSupport {
this: HttpService =>
@joseraya
joseraya / parallel.js
Created March 26, 2014 15:13
promises fun
var Q = require('q');
function printNumber(n) {
return Q.fcall(function () {
console.log("Number: ", n);
return n;
});
}
function printNumbers(numbers) {
@joseraya
joseraya / snapshot-crawler.js
Created January 21, 2014 20:15
A node script that crawls a web site and stores snapshots (taken with zombie.js) to the file system. Based on code from this article: http://www.ng-newsletter.com/posts/serious-angular-seo.html
var Browser = require('zombie'),
url = require('url'),
fs = require('fs'),
$q = require('Q'),
saveDir = __dirname + '/_snapshots';
var scriptTagRegex = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;
var stripScriptTags = function(html) {
@joseraya
joseraya / ConfigureBitbucketHookForJenkins.md
Created October 5, 2013 08:19
Configure Bitbucket hook for jenkins

In order to configure the bitbucket hook we need two things: The user's API Token and the project token. In order to retrieve the first one whe should click on our username (on the top right corner of the page), click on configure and then click on "Show API Token". This API token will be used as password for our user.

For the project's token we need to go to the job configuration (/job/{job-name}/configure), "build triggers" and enable "trigger remote builds" and, there, input some random text as token.

Once we have these two tokens we can go to bitbucket, repo administration, hooks section, and add a new jenkins hook that we will configure like:

  • Endpoint: http://{username}:{APIToken}@{hostname}/{prefix_if_you_have_one}
  • Module name: Whatever (I usually leave this one blank)
  • Project name: The job name
  • Token: The project token
@joseraya
joseraya / MockedApp.scala
Created October 3, 2013 18:57
Play framework mocked application: All the controllers are mocks and do nothing. Useful for testing routes. Defines a mocekdApp method that should be used like: "wathever" in mockedapp { //here you can call route(FakeRequest(...)) and use Mockito.verify or mustInvoke[Controllerclass].method(params) }
import play.api.test.Helpers._
import play.api.test._
import play.api.mvc.Result
import play.api.libs.json.JsValue
import play.api.libs.json.Json
import play.api.GlobalSettings
import org.mockito.stubbing.OngoingStubbing
import scala.reflect.ClassTag
import org.specs2.mock.Mockito
import play.api.mvc.Call
@joseraya
joseraya / watch
Created November 26, 2012 12:31
Watch a directory and execute something whenever a file is changed
#!/bin/sh
check() {
chsum1=chsum2
while [[ true ]]
do
chsum2=`find . -type f -exec md5 {} \;`
if [[ $chsum1 != $chsum2 ]] ; then
echo "Change detected ..."
@joseraya
joseraya / core_test.clj
Created June 8, 2012 12:33
Encapsulation in clojure
(ns encapsulation.core-test
(:use midje.sweet)
(:require [clj-time.core :as time]))
;My point here is to show how we can achieve encapsulation in clojure
;I assume that we may need encapsulation for two purposes:
; - Hide the internal representation of data (so that it can change)
; - Ensure the consistency of the data (by applying integrity constraints)
;Let's say that we have a "class" Person with an age.
@joseraya
joseraya / build.sbt
Created April 17, 2012 09:46
Empty sbt-idea project
organization := "com.agilogy"
name := "<<whatever>>"
version := "0.0.1"
scalaVersion := "2.9.1"
libraryDependencies += "org.scalatest" %% "scalatest" % "1.7.1" % "test"