Skip to content

Instantly share code, notes, and snippets.

import java.util.Date
import java.util.concurrent.ConcurrentLinkedDeque
import java.util.concurrent.atomic.AtomicLong
import scala.util.{Failure, Success, Try}
case class SimpleLimiterQueueItem(weight: Long, date: Date)
@mark-jay
mark-jay / jstatd.sh
Created June 14, 2020 10:52 — forked from nicerobot/jstatd.sh
Run jstatd w/o error 'access denied (java.util.PropertyPermission java.rmi.server.ignoreSubClasses write)'
#!/bin/sh
policy=${HOME}/.jstatd.all.policy
[ -r ${policy} ] || cat >${policy} <<'POLICY'
grant codebase "file:${java.home}/../lib/tools.jar" {
permission java.security.AllPermission;
};
POLICY
jstatd -J-Djava.security.policy=${policy} &
@mark-jay
mark-jay / USAGE.md
Last active March 23, 2020 12:38
xml to java generator

./xml-to-java.sh /path/to/package/directory

[
{
'repeat(5, 10)': {
_id: '{{objectId()}}',
index: '{{index()}}',
guid: '{{guid()}}',
isActive: '{{bool()}}',
balance: '{{floating(1000, 4000, 2, "$0,0.00")}}',
picture: 'http://placehold.it/32x32',
age: '{{integer(20, 40)}}',
@mark-jay
mark-jay / run-surveillance-server.py
Last active July 22, 2017 19:24
Simple http server that provides camera pictures on request
### installation:
# sudo apt-get install fswebcam autossh
#
### test camera:
# fswebcam -r 640x480 -S 25 --jpeg 85 -D 1 /tmp/web-cam-shot.jpg && opn /tmp/web-cam-shot.jpg
#
### running:
# PORT=10007
# autossh -M 20000 -f -N <YOUR_VPS> -R 8080:localhost:"$PORT" -C
# python run-surveillance-server.py "$PORT" "/tmp/webcam.jpg"
/*
Copyright 2016 <Mark Jay>
*/
#include <iostream>
#include <vector>
#include <cstdlib> // abs
#include <algorithm> // std::swap
#include <numeric> // std::accumulate
using std::cout;
// --------------------------------------------------------------------------------
// abstract generic stuff:
public abstract class AbstractEntity {
ID, hibernate-version, reflective to-string/equals/hashcode
}
public UIWindowFactory {
public <T extends AbstractEntity> AbstractUIWindow<T> getUIWindow(T entity) {...}
}
public abstract class AbstractUIWindow<T extends AbstractEntity> {
public com.vaddin.Window generateEditWindow(T entity) { generateDefaultReflectiveEditWindow(entity); }
@mark-jay
mark-jay / SSLPoke.java
Last active September 9, 2015 06:47 — forked from 4ndrej/SSLPoke.java
Test of java SSL / keystore / cert setup. Check the commet #1 for howto.
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.*;
/** Establish a SSL connection to a host and port, writes a byte and
* prints the response. See
* http://confluence.atlassian.com/display/JIRA/Connecting+to+SSL+services
*/
public class SSLPoke {
public static void main(String[] args) {
@mark-jay
mark-jay / reflect.py
Last active February 2, 2017 23:51 — forked from huyng/reflect.py
A simple echo server to inspect http web requests
#!/usr/bin/env python
# Reflects the requests from HTTP methods GET, POST, PUT, and DELETE
# Written by Nathan Hamiel (2010)
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from optparse import OptionParser
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
@mark-jay
mark-jay / curry.bash
Last active April 25, 2018 22:47 — forked from abesto/curry.bash
Partial application in Bash
function curry() {
exportfun=$1; shift
fun=$1; shift
params=$*
cmd=$"function $exportfun() {
more_params=\$*;
$fun $params \$more_params;
}"
eval $cmd
}