Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rhardih
rhardih / zip_file_names.rb
Last active April 25, 2021 23:21
Listing filenames of a remote ZIP archive without downloading entire file
require 'httparty'
require 'uri'
def get_file_names(zip_url)
# ZIP file format: https://en.wikipedia.org/wiki/ZIP_(file_format)
# 1. Do an initial head request to figure out how big the file is from the
# content size
response = HTTParty.head(zip_url)
@rhardih
rhardih / out.sh
Created November 22, 2017 14:23
http-server vs. http.listenAndServe scale
# http-server
rene $ for i in 16 128; do ab -c $i -n $i http://127.0.0.1:8080/ | grep "Time per"; done
Time per request: 20.492 [ms] (mean)
Time per request: 1.281 [ms] (mean, across all concurrent requests)
Time per request: 138.750 [ms] (mean)
Time per request: 1.084 [ms] (mean, across all concurrent requests)
# serve
rene $ for i in 16 128; do ab -c $i -n $i http://127.0.0.1:8080/ | grep "Time per"; done
Time per request: 3.465 [ms] (mean)
@rhardih
rhardih / call.sh
Last active October 25, 2017 11:32
valgrind callgrind Unrecognised instruction on macOS 10.12.6
valgrind --tool=callgrind ./oclinf
@rhardih
rhardih / Makefile
Created September 8, 2017 11:10
OpenCV cv::ocl::attachContext problem
INC=-I/Users/rene/Code/OpenCL-Headers/opencl12
PKG=`pkg-config --cflags --libs opencv`
LD=`pkg-config --libs-only-L opencv | cut -c 3-`
.PHONY: default a.out.lldb
default: build
LD_LIBRARY_PATH=$(LD) ./a.out
lldb: build a.out.lldb
LD_LIBRARY_PATH=$(LD) lldb --source a.out.lldb
@rhardih
rhardih / out.sh
Created November 22, 2016 14:26
Leptonica build fails to find include of custom compiled version of libjpeg
rene $ ls -la
total 0
drwxr-xr-x 2 rene staff 68 Nov 22 15:22 .
drwxr-xr-x 26 rene staff 884 Nov 22 14:15 ..
[~/Code/leptonica/build] (master)
rene $ tree ../dependencies/install/
../dependencies/install/
├── bin
│   ├── cjpeg
│   ├── djpeg
@rhardih
rhardih / rf.sh
Created November 20, 2016 17:08
List a random file from the current directory
ls | head -$(($RANDOM % `ls | wc -l` + 1)) | tail -1
@rhardih
rhardih / md5c.sh
Created November 2, 2016 11:42
Bash utility shorthand to validate md5 checksums on files
#!/usr/bin/env bash
# md5c
#
# Perform md5 checksum validation of a file against
# a specified md5 hash.
#
# usage: md5c filename hash
function md5c {
filename="$1"
@rhardih
rhardih / when.js
Created April 18, 2016 14:50
Simple handler class providing callbacks when dom objects scroll into view
var WhenHandler = function(id) {
this.elm = document.querySelector("#" + id);
this.scrolled_into_view = false;
this.scroll_callback;
this.doc = document.documentElement;
this.doc_bounds = this.doc.getBoundingClientRect();
this.elm_bounds = this.elm.getBoundingClientRect();
}
@rhardih
rhardih / pointer_fun.c
Created October 19, 2015 23:28
Simple example of manipulating contents of a pointer from within a function call.
#include <stdio.h>
#include <stdlib.h>
int pointer_pointer_function(int **pp)
{
printf("EQUAL WAYS OF ADDRESSING:\n");
printf("*(*pp + 0): %d\n", (int) *(*pp + 0));
printf("*(*pp + 1): %d\n", (int) *(*pp + 1));
printf("*(*pp + 2): %d\n", (int) *(*pp + 2));
@rhardih
rhardih / convert.sh
Created August 26, 2015 17:18
Recursively find and convert .epub to .mobi using calibres ebook-convert (in parallel)
find . -name "*.epub" -exec sh -c 'ebook-convert "{}" "$(dirname "{}")/$(basename -s .epub "{}").mobi" &' \;