Skip to content

Instantly share code, notes, and snippets.

View dclucas's full-sized avatar

Diogo Lucas dclucas

View GitHub Profile
@dclucas
dclucas / node-redis-sequence.js
Created December 21, 2015 00:30
Redis-based sequence generation in node.js
'use strict';
/*
initialize npm and make sure you add the required dependencies
$ npm init
$ npm install hapi ioredis redlock --save
}
*/
const Redlock = require('redlock');
const Redis = require('ioredis');
var client1 = new Redis();
@dclucas
dclucas / CommentResourceBuilder.groovy
Last active August 29, 2015 14:21
Example for resource builder class, consuming the DSL
class CommentResourceBuilder {
def buildResource(Resource resource) {
resource.definitions =
resource.definitions
.Comments {
properties {
body {
type 'string'
description 'Comments contents'
}
@dclucas
dclucas / defineResource.groovy
Last active August 29, 2015 14:21
Sample DSL usage, for v 0.1 of the language
resource.definitions.Comment {
properties {
id {
type 'Integer'
description 'The comment id'
}
name {
type 'String'
description 'The comment name'
}
// ----------------------------------------------
// Builder implementation and supporting classes.
// ----------------------------------------------
import groovy.transform.*
@Canonical
class Definition {
Map<String, Schema> schemas = [:]
def methodMissing(String name, args) {
@dclucas
dclucas / defineRoute02.groovy
Last active August 29, 2015 14:20
Second shot at the DSL draft
def defineRoute(routeBuilder) {
// defining a "categories" endpoint
routeBuilder."/categories" {
// defining the "Category" schema
schema Category {
properties {
// this is pure jsonschema, with a builder syntax
name {
type string
description "a name"
@dclucas
dclucas / defineRoute.groovy
Created May 11, 2015 12:44
Rough DSL usage draft for route condiguration
def defineRoute(routeBuilder) {
routeBuilder.categories {
schema {
properties {
name {
type string,
description "a name"
}
links {
brand "brands"
import groovy.text.SimpleTemplateEngine
def rawTemplate = '''CREATE OR REPLACE TRIGGER ${owner}.${entityName}_INSERT
AFTER INSERT
ON ${owner}.${tableName}
WHEN
${ columns.collect( { " old.$it <> new.$it" } ).join(/\n/) }
BEGIN
END'''
@dclucas
dclucas / spark-validation.groovy
Last active August 29, 2015 14:20
Spark server with json schema validation, running on groovy
@Grab('com.github.fge:json-schema-validator:2.2.6')
@Grab('com.sparkjava:spark-core:2.1')
import spark.*
import static spark.Spark.*
import com.github.fge.jackson.JsonLoader
import com.github.fge.jsonschema.main.JsonSchemaFactory
def factory = JsonSchemaFactory.byDefault()
var gulp = require('gulp');
gulp.task('mongo-eval', function() {
var Db = require('mongodb').Db,
Server = require('mongodb').Server,
assert = require('assert');
var db = new Db('local', new Server('localhost', 27017));
// Establish connection to db
db.open(function(err, db) {
sudo apt-get -y install git-flow
npm install -g mocha gulp gg ungit
sudo apt-get -y install zsh
sed -i "s/alias gg='git gui citool'/alias ggg='git gui citool'/g" ~/.oh-my-zsh/plugins/git/git.plugin.zsh