Skip to content

Instantly share code, notes, and snippets.

View leszekgruchala's full-sized avatar

Leszek Gruchała leszekgruchala

View GitHub Profile
@leszekgruchala
leszekgruchala / urlParser
Created April 6, 2012 08:10
Parser taken from JQuery Mobile, left just parser of URL
//Taken from JQuery Mobile
path = {
urlParseRE: /^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/,
parseUrl: function( url ) {
var matches = path.urlParseRE.exec( url || "" ) || [];
return {
href: matches[ 0 ] || "",
hrefNoHash: matches[ 1 ] || "",
hrefNoSearch: matches[ 2 ] || "",
domain: matches[ 3 ] || "",
@leszekgruchala
leszekgruchala / ResourcesCachingWrapper.java
Last active December 15, 2015 23:49
Http response wrapper for caching js, css and images for browsers.
package eu.gruchala.web.wrapper;
import java.util.Arrays;
import java.util.Calendar;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
/**
* Caches requests for all CSS, JS and images.
@leszekgruchala
leszekgruchala / dwrPromise.js
Last active November 18, 2015 01:07
DWR request wrapped by Promise
/**
* Creates promise object for DWR async calls.
* @param dwrFunc DWR function to be invoked
* @param arrayOfParameters [optional] parameters of given DWR function
* @returns {Q.promise}
*/
function qDwr(dwrFunc, arrayOfParameters) {
var deferred = Q.defer();
if (arrayOfParameters === undefined || arrayOfParameters === null) {
arrayOfParameters = [];
import scalaz.{Failure, Semigroup, Success, Validation}
object ScalazCustomOps {
implicit class ScalazValidationOps[+E, +A](validation: Validation[E, A]) {
/**
* Check both validations, in case of success of both return only one success result (the latter).
* Otherwise collect failures.
*
@leszekgruchala
leszekgruchala / Example.scala
Created April 25, 2020 10:03
ZStream.interruptWhen
import zio._
import zio.stream._
import zio.duration._
object TestStream extends App {
//There are few issues:
// 1. .interruptWhen(hook) //BOOM: With this, only 1 element of A will be processed, the program no longer processes anything
// 2. The program is unable to finish with status code 0
// 3. "Processes N element" never prints
[info] [hello-zio-http-graalvm:25] classlist: 52,244.48 ms, 0.96 GB
[info] [hello-zio-http-graalvm:25] (cap): 609.76 ms, 0.96 GB
[info] [hello-zio-http-graalvm:25] setup: 2,963.99 ms, 0.96 GB
[error] Error: Image build request failed with exit status 137
[error] com.oracle.svm.driver.NativeImage$NativeImageError: Image build request failed with exit status 137
[error] at com.oracle.svm.driver.NativeImage.showError(NativeImage.java:1676)
[error] at com.oracle.svm.driver.NativeImage.build(NativeImage.java:1426)
[error] at com.oracle.svm.driver.NativeImage.performBuild(NativeImage.java:1387)
[error] at com.oracle.svm.driver.NativeImage.main(NativeImage.java:1374)
[error] at com.oracle.svm.driver.NativeImage$JDK9Plus.main(NativeImage.java:1858)