Skip to content

Instantly share code, notes, and snippets.

View javierarilos's full-sized avatar

javier arias losada javierarilos

View GitHub Profile
@javierarilos
javierarilos / esprima-simplest-sample.js
Created July 22, 2015 10:12
Javascript simplest parsing with Esprima
var util = require('util');
var esprima = require('esprima');
var fs = require('fs');
var jscode = fs.readFileSync('./src/index.js').toString('utf8');
jscode = jscode.replace(/#!.*\n/,''); //remove shebang (executable js files)
console.log(jscode);
var tree = esprima.parse(jscode);
console.log(util.inspect(tree, {depth: 15, colors: true}));
// Dependency injection used in frameworks like Angular.js, Require.js, Inject.js
// There are 3 types of dependency injection : setter, constructor and interface injection.
// Needs: a container or injector which can provide dependencies we need.
// Reasons for DI: two main reason to favor dependency injection :
// * improve maintainability
// * make it easier to test
var Injector = {dependencies: {},
add : function(qualifier, obj){
this.dependencies[qualifier] = obj;},
@javierarilos
javierarilos / CollectionPipeline.js
Last active January 27, 2016 13:49
Main examples from Martin Fowler article on Collection Pipeline programming pattern with javascript and underscore.js
'use strict';
/**
* Implementing main examples from Martin Fowler article
* on Collection Pipeline programming pattern:
* http://martinfowler.com/articles/collection-pipeline/
* with #javascript and underscore.js: http://underscorejs.org/
*
* tested with nodejs v0.10.32
*
* underscore.js is required:
@javierarilos
javierarilos / micro-mongodb-python-book.py
Created May 22, 2014 21:47
The Little MongoDB Book code examples written in Python + pymongo
##########################################################################
# THE MICRO MONGODB+PYTHON BOOK
#
# A simple adaptation to Python + summary of
# The Little MongoDB Book: https://github.com/karlseguin/the-little-mongodb-book
#
# javier arias losada
# twitter: @javier_arilos
# Usage suggestion: run line by line bu using pydemo project (https://github.com/pablito56/pydemo)
@javierarilos
javierarilos / pymongo_dbref_example.py
Last active August 30, 2017 03:16
Based in the micro python+mongodb book examples, used mongodb DBRef to model employe => manager(s) relationships.
import pymongo
from pymongo import Connection
from bson.dbref import DBRef
from bson.objectid import ObjectId
from pymongo.database import Database
from datetime import datetime
client = pymongo.MongoClient()
# use micro database
db = client['micro']
/*
Proof of concept of starting Apache Camel routes.
Grabs all dependencies, starts Camel and adds two routes to it.
- Timer to console
- Websockets => RabbitMQ
Usage:
>>> groovy groovying_camel.groovy
End with CTRL+C
@javierarilos
javierarilos / rabbit_pika_introduction.py
Last active February 9, 2021 18:23
RabbitMq messaging concepts using Python + pika
from pika import BlockingConnection, ConnectionParameters, BasicProperties
##########################################################################
# RABBITMQ & AMQP INTRO - MESSAGING PATTERNS
# http://www.slideshare.net/javierarilos/rabbitmq-intromsgingpatterns
#
# ******** Escenario 1:
# *
# Using pika we are going to create a exchange named 'important', bind it to a queue named 'important-jobs'.
# Finally we will produce (to exchange) and consume (from queue) a message.
@javierarilos
javierarilos / py-code-update.py
Last active December 28, 2023 05:46
Sample of reloading a class definition in python. Old and new instances point to the correct class definition.
# writing c1 class definition to module mod1
cs = """
class c1(object):
att = 1
def m1(self):
self.__class__.att += 1
# printing class name, class-id, and the id of the class, which happens to be its memory address
print "uno:", self.__class__, "class-id:", id(self.__class__), "att:", self.__class__.att
"""
import py4j.GatewayServer;
public class FindForbiddenEntryPoint {
public class Finder{
public boolean jForbidden(String word, char forbidden_1){
return word.indexOf(forbidden_1) > -1;
}
}
Finder finder = null;
@javierarilos
javierarilos / scripting.java.sh
Created September 21, 2012 16:43
Scripting in java... edit your java class and execute it directly as a shell script.
#!/bin/bash
# "Scripting" java. Download jar dependencies if needed.
# execute it directly from command line: bash < <(curl -L -k https://raw.github.com/gist/3762558/b941980bf5cf6671c3ff1477982ce370015a8333/scripting.java.sh)
if [ ! -f junit-4.11-SNAPSHOT-20120805-1225.jar ];
then
wget --no-check-certificate https://github.com/downloads/KentBeck/junit/junit-4.11-SNAPSHOT-20120805-1225.jar
fi
cat <<-EOF > Scripting.java