Skip to content

Instantly share code, notes, and snippets.

@henrikno
henrikno / server.py
Last active March 4, 2021 20:46
Python Multithreaded TCP server example
#!/usr/bin/python
import socket # Import socket module
from threading import Thread
def on_new_client(clientsocket, addr):
try:
while True:
msg = clientsocket.recv(1024)
if not msg:
@henrikno
henrikno / gist:4eabd7a4cb5be2f37f9d86145e5cae39
Created April 30, 2020 00:07
Get current/max memory usage for java process
PID=$(jps | grep Main | awk '{print $1}')
CUR=$(jstat -gc $PID | tail -n 1 | awk '{split($0,a," "); sum=a[3]+a[4]+a[6]+a[8]; print sum/1024}')
MAX=$(jstat -gccapacity $PID | tail -n 1 | awk '{split($0,a," "); sum=a[2]+a[8]; print sum/1024}')
echo $CUR/$MAX
### Keybase proof
I hereby claim:
* I am henrikno on github.
* I am henrikno (https://keybase.io/henrikno) on keybase.
* I have a public key ASDW-yzrF0xb95QlVFxbM29dhaYqKlvyFAxIienhFwbzFQo
To claim this, I am signing this object:
@henrikno
henrikno / ElasticSearchTest.java
Created September 2, 2015 13:52
Elasticsearch bulk index with retry and failure check
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import org.elasticsearch.action.WriteConsistencyLevel;
import org.elasticsearch.action.bulk.BulkItemResponse;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
@henrikno
henrikno / MyListener.java
Created November 5, 2013 09:25
LeaderSelector
@Override
public void takeLeadership(CuratorFramework curatorFramework) throws Exception {
ourThread = Thread.currentThread();
logger.debug(format("(%s) Got leadership", ourThread));
try {
waitForAndPerformWork();
} catch (InterruptedException e) {
logger.debug(format("(%s) Interrupted ", ourThread), e);
} finally {
logger.debug(format("(%s) No longer leader", ourThread));
@henrikno
henrikno / gist:6966707
Created October 13, 2013 19:52
Building brave-zipkin-spancollector in maven 3.0.5
[INFO] ------------------------------------------------------------------------
[INFO] Building brave-zipkin-spancollector 2.0.3-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ brave-zipkin-spancollector ---
[INFO] Deleting /home/henrik/Dropbox/code/brave/brave-zipkin-spancollector/target
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ brave-zipkin-spancollector ---
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ brave-zipkin-spancollector ---
@henrikno
henrikno / logging
Last active December 24, 2015 05:49
ITRestEasyExample log
Running com.github.kristofa.brave.resteasyexample.ITRestEasyExample
16:20:16,183 INFO [main] server.Server (Server.java:270) - jetty-8.1.9.v20130131
16:20:16,352 INFO [main] webapp.StandardDescriptorProcessor (StandardDescriptorProcessor.java:282) - NO JSP Support for /RestEasyTest, did not find org.apache.jasper.servlet.JspServlet
16:20:16,534 INFO [main] handler.ContextHandler$Context (ContextHandler.java:2021) - Initializing Spring FrameworkServlet 'dispatcher'
16:20:16,534 INFO [main] servlet.FrameworkServlet (FrameworkServlet.java:454) - FrameworkServlet 'dispatcher': initialization started
16:20:16,552 INFO [main] support.AbstractApplicationContext (AbstractApplicationContext.java:510) - Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Sun Sep 29 16:20:16 CEST 2013]; root of context hierarchy
16:20:16,678 INFO [main] support.AnnotationConfigWebApplicationContext (AnnotationConfigWebApplicationContext.java:245) - Found 11 annotated classes in package [com.github.kr
#include "Font.h"
#include <GL/glew.h>
#include <cstdio>
#include <cassert>
#include <cstdlib>
void Font::SetHeight(float h) {
m_height = h;
}
@henrikno
henrikno / PortAudio.cpp
Created May 24, 2013 18:46
Sound + FT-example
#include "PortAudio.h"
#include <portaudio.h>
#include <cstdio>
float spec_left[512];
float spec_right[512];
PortAudio::PortAudio() {
PaError err;
err = Pa_Initialize();
@henrikno
henrikno / record-desktop.sh
Created May 1, 2012 18:09
ffmpeg record scripts
#!/bin/bash -x
INRES="1920x1200"
OUTRES="1280x720"
FPS="30"
ffmpeg -f x11grab -s "$INRES" -r "$FPS" -i :0.0 -f alsa -ac 2 \
-i default -vcodec libx264 -s "$OUTRES" \
-acodec libmp3lame -ab 128k -ar 44100 \
-threads 0 -f flv $1