Skip to content

Instantly share code, notes, and snippets.

View beradrian's full-sized avatar

Adrian Ber beradrian

View GitHub Profile
<select >
<option th:each="year : ${#numbers.sequence(1900, #dates.year(#dates.createNow()))}"
th:value="${year}" th:text="${year}">
</option>
</select>
@beradrian
beradrian / PaypalExample.java
Last active September 10, 2015 22:26
Paypal API call with HttpClient
private static String paypalApiUrl = "https://api-3t.sandbox.paypal.com/nvp"; // remove sandbox. for production environment
private static NumberFormat paypalNumberFormat = new DecimalFormat("0.00", new DecimalFormatSymbols(Locale.US));
public Map<String, String> paypalApi(Map<String, Object> params) throws ClientProtocolException, IOException {
HttpClient client = httpClientBuilder.build();
HttpPost post = new HttpPost(paypalApiUrl);
List<NameValuePair> nvpParams = new ArrayList<NameValuePair>();
for (Map.Entry<String, ?> e : params.entrySet()) {
nvpParams.add(new BasicNameValuePair(e.getKey(), e.getValue() instanceof Number
? paypalNumberFormat.format(e.getKey()) : e.getValue().toString()));
@beradrian
beradrian / stuns
Created October 29, 2015 11:19 — forked from yetithefoot/stuns
STUN+TURN servers list
{url:'stun:stun01.sipphone.com'},
{url:'stun:stun.ekiga.net'},
{url:'stun:stun.fwdnet.net'},
{url:'stun:stun.ideasip.com'},
{url:'stun:stun.iptel.org'},
{url:'stun:stun.rixtelecom.se'},
{url:'stun:stun.schlund.de'},
{url:'stun:stun.l.google.com:19302'},
{url:'stun:stun1.l.google.com:19302'},
{url:'stun:stun2.l.google.com:19302'},
@beradrian
beradrian / xmlhttprequest.js
Created November 25, 2015 15:17 — forked from yocontra/xmlhttprequest.js
Tiny XMLHTTPRequest shim
var ids = ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP", "Msxml2.XMLHTTP.4.0"];
if (typeof XMLHttpRequest === "undefined") {
for (var i = 0; i < ids.length; i++) {
try {
new ActiveXObject(ids[i]);
window.XMLHttpRequest = function() {
return new ActiveXObject(ids[i]);
};
break;
} catch (e) {}
@beradrian
beradrian / DistanceTest.java
Created December 3, 2015 14:41
Distance between two geographical points
package org.bar;
import org.geotools.referencing.GeodeticCalculator;
import java.awt.geom.Point2D;
/**
* How far is NY from London ?
*/
public class DistanceTest {
@beradrian
beradrian / WebsocketsConfig.java
Created June 15, 2016 08:46
Websockets config
package com.stefisoft.webchat;
import java.util.HashSet;
import java.util.Set;
import javax.websocket.Endpoint;
import javax.websocket.server.ServerApplicationConfig;
import javax.websocket.server.ServerEndpointConfig;
import org.slf4j.Logger;
@beradrian
beradrian / .travis.yml
Last active June 23, 2016 15:29
Karma with Chrome and FF on Travis
language: node_js
node_js:
- stable
before_install:
- export CHROME_BIN=/usr/bin/google-chrome
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sudo apt-get update
- sudo apt-get install -y libappindicator1 fonts-liberation
- sudo apt-get upgrade libstdc++6 lsb-base
@beradrian
beradrian / FineTuneCache.nginx.conf
Created May 19, 2017 10:41
Nginx configuration
# https://www.nginx.com/blog/nginx-caching-guide/
proxy_cache_path /path/to/cache levels=1:2 keys_zone=my_cache:10m max_size=10g
inactive=60m use_temp_path=off;
server {
...
location / {
proxy_cache my_cache;
@beradrian
beradrian / build.gradle
Last active May 25, 2017 13:32 — forked from xconnecting/build.gradle
Gradle: Using jdbc in build script
import groovy.sql.Sql
// more information at http://docs.groovy-lang.org/latest/html/api/groovy/sql/Sql.html
apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'maven'
repositories { mavenCentral() }
configurations { driver }
@beradrian
beradrian / chronos.docker-compose.yml
Last active May 25, 2017 13:38
docker-compose.yml samples
version: '3'
services:
zk1:
image: zookeeper
restart: always
ports:
- "2181:2181"
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=zk1:2888:3888