Skip to content

Instantly share code, notes, and snippets.

View ataube's full-sized avatar

Andreas Taube ataube

  • collect.ai
  • Hamburg
View GitHub Profile
@ataube
ataube / argsToArray.js
Created October 21, 2012 18:30
Dynamically converts function args to an array
var myFunction = function() {
var args = Array.prototype.slice.call(arguments, 0, arguments.length);
//do and return something
}
@ataube
ataube / batch_rename.sh
Created November 23, 2012 09:44
Svn Batch Rename
#!/bin/bash
for i in *.tpl; do
j=`echo $i | sed 's/.tpl/.hbs/g'`;
svn ren $i $j;
done
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
connect: {
server: {
options: {
port: 9001,
@ataube
ataube / angular_srv_fac_prov_patterns.js
Created December 29, 2012 16:56
Difference between Angular service, factory and provider pattern Taken from http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
};
});
//factory style, more involved but more sophisticated
@ataube
ataube / JsonObjectMapper.java
Created January 3, 2013 14:52
Spring 3.2 Custom JSON Serialization with Jackson ObjektMapper with XML Configuration
//imports...
public class JsonObjectMapper extends ObjectMapper {
@Autowired
WebApplicationContext context;
public JsonObjectMapper() {
SimpleModule module = new SimpleModule();
module.addSerializer(MyDomainType.class, new TestSerializer(context));
@ataube
ataube / gist:bedee4779bad072a3fa9
Last active August 29, 2015 14:16
Spring Date Rest - Custom Deserialization with entity associations problem
@Entity
public class EntityA {
private String name;
}
@Entity
public class EntityB {
@OneToOne
private EntityA entityA;
@ataube
ataube / gist:1841a4e83991643be04e
Last active February 4, 2016 10:07
Helpful Hadoop and stuff commands
yarn logs -applicationId ...
spark-submit --master yarn-cluster --driver-class-path /usr/share/java/mysql-connector-java.jar --jars /usr/share/java/mysql-connector-java.jar,/usr/hdp/2.3.4.0-3485/spark/lib/datanucleus-core-3.2.10.jar,/usr/hdp/2.3.4.0-3485/spark/lib/datanucleus-rdbms-3.2.9.jar,/usr/hdp/2.3.4.0-3485/spark/lib/datanucleus-api-jdo-3.2.6.jar --files /etc/spark/2.3.4.0-3485/0/hive-site.xml myapp.py
@ataube
ataube / transaction.js
Created August 14, 2016 20:25
Loopback async/await transaction example
const Transaction = require('loopback-datasource-juggler');
const update = async (ids, delta) => {
const result = [];
const tx = await models.MyModel.beginTransaction({ isolationLevel: Transaction.READ_COMMITTED });
try {
for (const id of ids) {
const entity = await updateById(id, delta, { transaction: tx });
result.push(entity);
}
@ataube
ataube / stream-transform.js
Created January 5, 2017 16:03
Transforms a Json file and write the output back
const fs = require('fs');
const es = require('event-stream');
const JSONStream = require('JSONStream');
const inStream = fs.createReadStream('tests/fixtures/claims10k.json');
const outStream = fs.createWriteStream('tests/fixtures/claims10kPatched.json');
const map = es.mapSync((d) => {
const email = `${d.debtorName.toLowerCase()}.${d.debtorLastName.toLowerCase()}@email.com`;
return Object.assign({}, d, { email });
@ataube
ataube / compose.js
Created February 4, 2017 12:19
ES6 based function composition
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));