Skip to content

Instantly share code, notes, and snippets.

View chbaranowski's full-sized avatar

Christian Baranowski chbaranowski

View GitHub Profile
@chbaranowski
chbaranowski / EchoTest.java
Created December 10, 2011 12:37
Cheat Sheet Test for Mockito
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.is;
import static org.mockito.Mockito.*;
import static org.mockito.BDDMockito.*;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
@chbaranowski
chbaranowski / MongoDecodeBase64.js
Last active August 14, 2021 09:04
MongoDB query decode Base64 document property raw-data
var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(e){var t="";var n,r,i,s,o,u,a;var f=0;e=Base64._utf8_encode(e);while(f<e.length){n=e.charCodeAt(f++);r=e.charCodeAt(f++);i=e.charCodeAt(f++);s=n>>2;o=(n&3)<<4|r>>4;u=(r&15)<<2|i>>6;a=i&63;if(isNaN(r)){u=a=64}else if(isNaN(i)){a=64}t=t+this._keyStr.charAt(s)+this._keyStr.charAt(o)+this._keyStr.charAt(u)+this._keyStr.charAt(a)}return t},decode:function(e){var t="";var n,r,i;var s,o,u,a;var f=0;e=e.replace(/[^A-Za-z0-9+/=]/g,"");while(f<e.length){s=this._keyStr.indexOf(e.charAt(f++));o=this._keyStr.indexOf(e.charAt(f++));u=this._keyStr.indexOf(e.charAt(f++));a=this._keyStr.indexOf(e.charAt(f++));n=s<<2|o>>4;r=(o&15)<<4|u>>2;i=(u&3)<<6|a;t=t+String.fromCharCode(n);if(u!=64){t=t+String.fromCharCode(r)}if(a!=64){t=t+String.fromCharCode(i)}}t=Base64._utf8_decode(t);return t},_utf8_encode:function(e){e=e.replace(/rn/g,"n");var t="";for(var n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r
@chbaranowski
chbaranowski / build.gradle
Created March 26, 2015 06:40
Gradle bnd build example
buildscript {
repositories {
ivy {
url 'https://bndtools.ci.cloudbees.com/job/bnd.master/lastSuccessfulBuild/artifact/dist/bundles'
layout 'pattern', { artifact '[module]/[artifact]-[revision].[ext]' /* OSGi repo pattern */ }
}
}
dependencies { classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:3.0.0' }
}
@chbaranowski
chbaranowski / SampleStackTest.java
Created June 2, 2011 09:32
Logging in JUnit Tests
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import java.util.Stack;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.MethodRule;
import org.junit.rules.TestWatchman;
@chbaranowski
chbaranowski / SorterTest.java
Last active March 29, 2021 11:00
JUnit3 simple example.
import java.util.Arrays;
import junit.framework.TestCase;
public class SorterTest extends TestCase {
Sorter<Integer> sut;
protected void setUp() throws Exception {
sut = Quicksort.createIntSorter();
@chbaranowski
chbaranowski / ContentController.java
Created October 4, 2017 19:04
SSE Spring and Angular
@RequestMapping("/api/v1/content")
@RestController
public class ContentController {
@Autowired
ContentRepository contentRepository;
private final List<SseEmitter> emitters = new ArrayList<>();
@RequestMapping(path = "/stream", method = RequestMethod.GET)
@chbaranowski
chbaranowski / pom.xml
Created May 13, 2011 16:54
Replace a String value of a property in Apache Maven (Workaround)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.seitenbau.demo.maven</groupId>
<artifactId>maven-properties-replace</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
@chbaranowski
chbaranowski / Demo Table DSL
Created April 24, 2013 19:58
Simple Table DSL.
fistname | lastname | job
"Christian" | "Baranowski" | "Developer"
"James" | "Bond" | "Agent"
@chbaranowski
chbaranowski / align.scss
Last active February 5, 2018 23:10
CSS3 and HTML - Vertical Text Alignment Options
/**
* Atom text center
*/
.text--center {
text-align: center;
width: 100%
}
/**
* Atom box
@chbaranowski
chbaranowski / http-client.ts
Created January 21, 2017 21:30
Use Angular2 Http service outside of Angular.
export class NoXSRFStrategy extends XSRFStrategy {
configureRequest(req: Request) { }
}
// HTTP configuration to use the http service outside of angular2.
const HTTP_PROVIDERS = [
{provide: XSRFStrategy, useClass: NoXSRFStrategy},
{provide: Http, useFactory:
(xhrBackend: XHRBackend, requestOptions: RequestOptions): Http =>
new Http(xhrBackend, requestOptions),