Skip to content

Instantly share code, notes, and snippets.

@AlexMocioi
AlexMocioi / test.java
Created May 13, 2017 04:35
Junit and Mockito example
@Test public void fromCen2FattPAConversionShouldCreateCsvIfConversionResultHasErrors() throws IOException, SyntaxErrorInInvoiceFormatException {
// given
given( fromCen.extension() ).willReturn(".xml");
List<Exception> myErrors = Arrays.asList(new IllegalArgumentException("test exception"));
//Cen2FattPAConverter fromCen = Mockito.mock(Cen2FattPAConverter.class);
when(fromCen.convert(any())).thenReturn(new ConversionResult("bytes".getBytes(), myErrors));
// when converting a mock invoice, errors should occur
@AlexMocioi
AlexMocioi / GitFlow
Created April 27, 2017 15:50
How to use Git better, not just push and pull and commit
In git flow, usually there's one branch per feature.
So, you should:
- synch your local develop with remote develop.
- start a new feature from your local develop
#!/bin/bash
url="http://HOST:8098/buckets/apia2014/index/\$key/VerificareFinalaCA_ZDB_BIHOR_20150615075705_BH000000_vioril.pdf/VerificareFinalaCA_ZDB_BIHOR_20150615075705_BH009999_vioril.pdf"
FILE="keysJudet.txt"
result="$(curl -s $url)"
echo "$result">$FILE
keys="$(cat $FILE | jq '.keys')"
echo "$keys"
for i in $keys; do
i="${i/\"/}"
@AlexMocioi
AlexMocioi / ClientRMI.java
Created April 25, 2015 08:28
In cazul de fata am folosit o proprietate de pe adnotare ca sa ma asigur ca numele cu care este expus serviciul este acelasi cu cel dupa care il caut. mai departe mai ai nevoie de url-ul unde sa il caute (aici se calculeaza in RemoteParams.getRmiServerUrls(serviceName)) si de interfata bean-ului de spring. Pentru cazul in care ai bean-urile si l…
@Bean
public ClinicalDocumentService clinicalDocumentService() {
String serviceName = ((RemotableInterface) ClinicalDocumentService.class.getAnnotation(RemotableInterface.class)).serviceName();
RmiLbServiceConfig<ClinicalDocumentService> serviceConfig = new RmiLbServiceConfig<ClinicalDocumentService>(
RemoteParams.getRmiServerUrls(serviceName), ClinicalDocumentService.class);
serviceConfig.setMonitorPeriod(60L);
serviceConfig.setLookupStubOnStartup(true);
RmiProxyFactory factory = RmiProxyFactory.getInstance();
return factory.create(serviceConfig);
@AlexMocioi
AlexMocioi / selectCouch.js
Created September 12, 2014 15:01
Simulează o clauză WHERE complexă din SQL, funcției _list i se trimite ca parametru pe linia de comandă sursa în JavaScript pentru condiția de selecție. Se folosește mai jos cuplarea funcției _list pe view-ul implicit _all_docs Avantaje: filtrarea înregistrărilor se face remote, pe server, volumul de date trimis e minimal funcția de selecție poa…
function(head,req) {
var testFunc = function(doc) { return true; };
if ( typeof req.query['function'] !== 'undefined' ) {
// includ aici funcția de test trimisă
eval("testFunc = function(doc) { return "+req.query['function']+"; }");
}
start({ "headers": {"Content-type":"application/json;charset=utf-8", "Cache-Control": "max-age=10, must-revalidate"}});
send('{"offset":0,');
send('"rows":[\n');
var r2=false;
@AlexMocioi
AlexMocioi / compatible.js
Created September 12, 2014 14:34
Ăsta e codul de compatibilizare în spate pentru jQuery când o ia la pachet !!!
jQuery.browser={};
(function() {
jQuery.browser.msie=false;
jQuery.browser.version=0;
if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
jQuery.browser.msie=true;
jQuery.browser.version=RegExp.$1;
}
})();
@AlexMocioi
AlexMocioi / beanstalk_conf
Created May 30, 2014 06:01
Cum se configureaza un beanstalkd care sa ramana viu permanent ...
Leave beanstalkd disabled in /etc/default/beanstalkd
Then create a bash script to execute beanstalkd.
$ cat /usr/local/bin/beanstalkdshell
#!/bin/bash
/usr/local/bin/beanstalkd -l 0.0.0.0 -p 11300 -b /var/lib/beanstalkd
Then setup supervisord.
@AlexMocioi
AlexMocioi / Aduna11.rb
Created May 23, 2014 12:29
Ruby Gearman Worker
#!/usr/bin/env ruby
require 'rubygems'
require 'gearman'
require 'json'
require 'net/http'
require 'uri'
require 'pg'
w = Gearman::Worker.new(['***.***.***.***:4730'])
@AlexMocioi
AlexMocioi / Aduna11.java
Created May 23, 2014 12:21
Java Gearman Worker
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package aduna11java;
import org.gearman.Gearman;
import org.gearman.GearmanFunction;
/*
HTML5 Web Workers are the web’s answer to multi-threading. They’ve been around for a while now, so are pretty safe to rely on. A Worker is typically initialised by instantiating Worker with the URL of your ‘worker script’:
*/
var myWorker = new Worker('path/to/my/worker.js');
/*
And then you’d interface with the worker via asynchronous message-passing:
*/
// == Within parent page ==
myWorker.postMessage('Did you receive this?');