Skip to content

Instantly share code, notes, and snippets.

View beradrian's full-sized avatar

Adrian Ber beradrian

View GitHub Profile
@beradrian
beradrian / ServletUtils.java
Last active April 18, 2024 23:45
Get baseUrl for a servlet request
String getBaseUrl(HttpServletRequest request) {
String baseUrl = request.getRequestURL().substring(0, request.getRequestURL().length() - request.getRequestURI().length()) + request.getContextPath();
return baseUrl;
}
@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()));
<select >
<option th:each="year : ${#numbers.sequence(1900, #dates.year(#dates.createNow()))}"
th:value="${year}" th:text="${year}">
</option>
</select>
@beradrian
beradrian / sync-gh-pages
Last active June 8, 2017 19:50
Sync master into gh-pages
git checkout gh-pages
git merge master
git push origin gh-pages
@beradrian
beradrian / setproxy
Last active November 11, 2024 13:00
Set proxy for npm and git
# set a proxy
set HTTP_PROXY=
set HTTPS_PROXY=%HTTP_PROXY%
npm config set proxy %HTTP_PROXY%
npm config set https.proxy %HTTPS_PROXY%
npm config set https-proxy %HTTPS_PROXY%
git config --global http.proxy %HTTP_PROXY%
git config --global https.proxy %HTTPS_PROXY%
# unset proxy
@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