Skip to content

Instantly share code, notes, and snippets.

View kwikwag's full-sized avatar

kwikwag kwikwag

  • Developer of the world
View GitHub Profile
@kwikwag
kwikwag / HelloPrint.java
Created April 10, 2012 10:56
sample print app trying to monitor a print job in progress
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.net.URI;
import java.util.Date;
import java.util.Locale;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
IPP Printer : HL2240D-local
IPP Printer : HL2240D
IPP Printer : HP-LaserJet-4050
printDataTransferCompleted
106
PrintEvent on sun.print.UnixPrintJob@107ebe1
printDataTransferCompleted
106
PrintEvent on sun.print.UnixPrintJob@107ebe1
PrintJobEvent: printJobNoMoreEvents
@kwikwag
kwikwag / jqm-make-bugs.html
Created August 31, 2012 04:27
for JQM bug: dynamic listview creation in a multipage doc fails if page has no '.ui-page' class
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
<style type="text/css">
</style>
<script type="text/javascript">
function make_bugs() {
$('#container').html(
@kwikwag
kwikwag / closest.m
Created June 9, 2013 23:01
Creates a matrix with the same dimensions as 'needle', placing in each element the closest value from 'haystack'; thanks to http://stackoverflow.com/users/279858/bill-cheatham
function [val, i] = closest(haystack, needle)
[~, i] = min(abs( ...
repmat(reshape(haystack,numel(haystack),1),1,numel(needle)) - ...
repmat(reshape(needle,1,numel(needle)),numel(haystack),1) ...
), [], 1);
val = reshape(haystack(i), size(needle));
end
@kwikwag
kwikwag / link-config-files.sh
Last active December 21, 2015 14:39
suggestion for maintaining config of a system: maintain a list all manually-edited files (/opt/admin/config/FILES), use this script with suggested cron jobs to keep a hierarchy of config files in this central place which is also easy to back up
@kwikwag
kwikwag / backup-dir.sh
Last active December 21, 2015 14:39
simple script to backup a directory as a tar.gz archive
#!/bin/bash
OUT_DIR=/opt/DUMP
VERBOSE=0
NAME=
show_help() {
cat <<HELP
Backs up a directory.
Usage: $0 [-h -?] [-n name] [-o outdir] <directory> [...tar options]
#!/usr/bin/env python
def is_int1(v):
return v.lstrip('+-').isdigit()
def is_int2(v):
try:
int(v)
return True
except ValueError:
#!/usr/bin/env python
import re
import fastnumbers
def is_int1(v):
try:
int(v)
return True
except ValueError:
import timeit
from math import pow
import sys
# Python 2/3 compatible
# note : alternative versions of this file had pow(x,0.33) replaced with
# sqrt(x) or max(x,33,1,2,3,4,5,6,6,7,8,9) to see the effect of the
# number of arguments on run times.
@kwikwag
kwikwag / test-split-tail-head.py
Created May 12, 2017 17:53
Python: splitting a string into two parts at the nth delimiter
from timeit import timeit
import re
def a(s, delim, n):
'''
Two-param split, retaining head
'''
r = s.split(delim, n)[n]
return s[:-len(r)-len(delim)], r