Skip to content

Instantly share code, notes, and snippets.

@smcl
smcl / findexec.js
Last active September 7, 2016 09:00
jjs demo - find all executable files in a directory using Nashorn/Java. Inspired by http://www.ibm.com/developerworks/library/l-linux-shells/
/*
findexec.js
demo of jjs, takes a single argument - a folder in which to search
for executable files, which will be printed to stdout.
example:
$ jjs ./filerev.js -- /usr/bin
@smcl
smcl / plotstdin.js
Created September 7, 2016 07:12
Another jjs demo - use javafx libraries to display a line graph of values read from stdin
/*
stdinplot.js
demo of jss usage - reads numbers from stdin and displays a dynamically
scaling line graph. ignores non-numerical values.
example:
$ jjs -fx stdinplot.js < sin_values.txt
*/
@smcl
smcl / img.js
Created August 30, 2016 20:04
Example of using jjs/nashorn and JavaFX to produce a pattern
// import statements
var ByteBuffer = java.nio.ByteBuffer;
var Application = javafx.application.Application;
var Group = javafx.scene.Group;
var Scene = javafx.scene.Scene;
var Canvas = javafx.scene.canvas.Canvas;
var GraphicsContext = javafx.scene.canvas.GraphicsContext;
var DropShadow = javafx.scene.effect.DropShadow;
var PixelFormat = javafx.scene.image.PixelFormat;
var PixelWriter = javafx.scene.image.PixelWriter;
@smcl
smcl / filerev.js
Created August 29, 2016 21:35
simple example of jjs - utility to invoke the Nashorn engine, which is a Java 8 implementation of es5/6 which can utility Java classes
/*
filerev.js
demo of jjs, takes stdin or list of files and takes entirety of buffer
or list of files, reads them into memory and prints them in reverse order.
awful code, purely to demonstrate the interaction between js and Java in the
Nashorn platform.
example 1:
@smcl
smcl / strcat_bench.py
Last active July 21, 2016 18:53
deleting unnecessary loads/stores speeds up string concatenation by 5-6%
#!/usr/bin/python
# Demonstration of two different optimisations which can be applied to the bytecode
# python generates for two differnent string concatenation techniques.
import time
from byteplay import *
loop_count = 1000000
#!/usr/bin/python
from cStringIO import StringIO
import time, commands, os
from sys import argv
def method1():
out_str = ''
for num in xrange(loop_count):
out_str += `num`
@smcl
smcl / ps4_lightbar.sh
Last active July 4, 2016 15:21
find the connected PS4 controller's LED devices, then cycle through a whole bunch of colours
#!/bin/bash
# this is a completely horrible hack to get the LED device - I have no idea how to get the
# actual device name from /sys/class/leds
ledPattern="[0-9A-F]{4}:[0-9A-F]{4}:[0-9A-F]{4}\.[0-9A-F]{4}:"
deviceName=`ls -1 /sys/class/leds | grep -E $ledPattern | sed -r "s/:\w+$//" | head -n 1`
function setLED {
echo $1 > /sys/class/leds/$deviceName:$2/brightness
}
@smcl
smcl / ps4_cube.py
Last active August 13, 2019 11:16
Demo of a number of ways the PS4 controller can interact with a pygame/opengl app. Hacked together and poorly written - just a demo/reference
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
surfaces = (
(1, 2, 3, 4),
(3, 2, 7, 6),
(6, 7, 5, 4),
(4, 5, 1, 0),
@smcl
smcl / svgalib.patch
Created June 23, 2016 22:33
Patch to build svgalib as i386 lib on linux
diff -bur svgalib-1.4.3/gl/Makefile svgalib-1.4.3-smcl/gl/Makefile
--- svgalib-1.4.3/gl/Makefile 1999-07-18 10:14:45.000000000 +0200
+++ svgalib-1.4.3-smcl/gl/Makefile 2016-06-24 00:11:39.368615455 +0200
@@ -29,7 +29,7 @@
.PHONY: all clean dep
libvgagl.so.$(VERSION): $(MODULES)
- $(CC) -s -shared -Wl,-soname,libvgagl.so.$(MAJOR_VER) -o libvgagl.so.$(VERSION) \
+ $(CC) -m32 -s -shared -Wl,-soname,libvgagl.so.$(MAJOR_VER) -o libvgagl.so.$(VERSION) \
$(MODULES)
@smcl
smcl / turdcircle.sh
Last active December 17, 2016 20:40
#!/bin/bash
# create four fifos connected in a ring, and fire the word "turd" into it
# because reasons
mkfifo pipe1
mkfifo pipe2
mkfifo pipe3
mkfifo pipe4
echo turd > pipe1 &