Skip to content

Instantly share code, notes, and snippets.

View lachlan's full-sized avatar

Lachlan Dowding lachlan

  • Brisbane, Australia
View GitHub Profile
@lachlan
lachlan / disable_scroll_up_event_propogation.js
Last active March 9, 2024 00:59
Disable scroll up events propagating to stop scroll jacking showing page header on scroll up like on Medium or Substack sites
window.____addEventListener____ = window.addEventListener;
window.addEventListener = function(type, listener, options) {
if (type === "scroll") {
____listener____ = listener;
previousScrollY = 0;
listener = function(event) {
if (window.scrollY >= previousScrollY) {
____listener____(event);
}
previousScrollY = window.scrollY;
@lachlan
lachlan / https_post_with_statistics.rb
Last active February 21, 2016 22:21
Threaded HTTP POST of content to an HTTP Server returning response duration statistics
# https post a payload to a web server with basic authentication
require 'net/https'
require 'benchmark'
request_count = 1
thread_count = 10
protocol = 'http' # or 'https'
host = 'www.example.com'
port = 80
path = '/path/file'
@lachlan
lachlan / Main.java
Created March 26, 2015 00:38
Split a large XML file into smaller XML files by a given element name
package com.github.lachlan.xml.splitter;
public class Main {
public static final int BUFFER_SIZE = 8192;
public static void main(String[] args) {
Main main = new Main();
if (args.length < 2) {
System.out.println("Usage: ");
@lachlan
lachlan / cereal.go
Created April 9, 2014 21:54
Writes data to a serial port
package main
import (
"encoding/base64"
"encoding/hex"
"github.com/docopt/docopt.go"
"github.com/tarm/goserial"
"log"
"strconv"
)
@lachlan
lachlan / counter.rb
Last active December 15, 2015 07:58
Counts the occurrence of elements and attributes in an XML corpus
require 'nokogiri'
# SAX parser which counts the occurrence of elements and
# attributes in an XML document
class Counter < Nokogiri::XML::SAX::Document
attr_reader :counts
def initialize
@counts, @path, @content = Hash.new(0), [], ''
end
@lachlan
lachlan / words.txt
Created September 28, 2012 00:37
Dictionary file from Mac OS X listing english words
This file has been truncated, but you can view the full file.
A
a
aa
aal
aalii
aam
Aani
aardvark
aardwolf
@lachlan
lachlan / anagrams.js
Created September 28, 2012 00:35
Find all the anagrams in a dictionary file
var fs = require('fs'),
filename = 'words.txt',
encoding = 'utf-8';
fs.readFile(filename, encoding, function(err, data) {
if (err) throw err;
var lines = data.split('\n');
// trim whitespace, and convert to lower case
@lachlan
lachlan / anagrams.rb
Created September 28, 2012 00:33
Find all the anagrams in a dictionary file
filename = "words.txt"
words = []
class String
def is_anagram?(other)
self.length == other.length && self.chars.sort == other.chars.sort
end
end
# build a list words from the file
@lachlan
lachlan / Pipeline.java
Created June 26, 2012 23:33
What the webMethods Integration Server pipeline looks like as Java
// Every webMethods Integration Server service has exactly one input
// argument: the pipeline.
//
// The pipeline is like a java.util.Map object that gets passed to each
// service that gets called. (It's actually a com.wm.data.IData object,
// which unfortunately doesn't implement java.util.Map.)
//
// Because objects are passed by reference, every service called can alter
// the keys and values in the pipeline.
//
@lachlan
lachlan / pipeline.js
Created June 25, 2012 01:25
What the webMethods Integration Server pipeline looks like as javascript
// Every webMethods Integration Server service has exactly one input
// argument: the pipeline.
//
// The pipeline is like a javascript object that gets passed to each
// service that gets called. (It's actually a com.wm.data.IData object,
// which is essentially a hash table.)
//
// Because objects are passed by reference, every service or function
// called can alter the keys and values in the pipeline.
//