Skip to content

Instantly share code, notes, and snippets.

@nickrussler
nickrussler / wait_for_mem_available.sh
Last active October 6, 2020 13:28
Wait with bash for some amount of memory (MemAvailable) to be available
#!/bin/bash
# Wait for MemAvailable to be bigger than a certain value.
#
# $1 - Value in kb that MemAvailable should be greater than.
# $2 - (Optional, Default=60) Timeout in seconds
#
# Examples
#
# wait_for_mem_available 10000000 120
@nickrussler
nickrussler / test.py
Created September 9, 2020 11:50
Test for browser handling of duplicate GET requests for the same resource
#!/usr/bin/python
# coding: utf-8
import time
from flask import Flask, make_response
from waitress import serve
import random
app = Flask(__name__)
@nickrussler
nickrussler / ics-filter.php
Last active May 13, 2016 13:34
Snippet to filter AirBnB Not available events and fix the end date
<?php
$ch = curl_init("https://www.airbnb.de/calendar/ical/XYZ");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
@nickrussler
nickrussler / XkbConfigRegistry.java
Last active August 29, 2015 14:27
Class to get XKB keyboard models and layouts with JAXB
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
@nickrussler
nickrussler / self-update.js
Created May 23, 2015 17:25
Programatically self-update a Firefox Addon
const self = require('sdk/self');
const chrome = require('chrome');
/**
* Autoupdate this addon on startup
*/
(function() {
let AddonManager = chrome.Cu.import('resource://gre/modules/AddonManager.jsm', null).AddonManager;
AddonManager.getAddonByID(self.id, function(addon) {
@nickrussler
nickrussler / Example.java
Last active February 11, 2022 16:01
String replace with callback in Java (like in JavaScript)
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
String result = StringReplacer.replace("Hello World!", Pattern.compile("\\d+"), m -> ("" + (Integer.parseInt(m.group()) * 2));
}
}
@nickrussler
nickrussler / gist:47acd2fd6ee316a00d26
Last active August 29, 2015 14:09
Set Windows file attribute hidden using Firefox SDK API
/**
* Sets the hidden file attribute of a file
* @param {String} filepath String holding the path of the file to hide
* @returns {Boolean} true if file attribute hidden is set, else false
*/
function setWindowsFileAttributeHidden(filepath) {
const FILE_ATTRIBUTE_HIDDEN = 0x00000002;
try {
chrome.Cu.import('resource://gre/modules/ctypes.jsm');
@nickrussler
nickrussler / gist:8355398
Created January 10, 2014 14:42
Upload file with jquery and formdata (untested, should work)
/**
* Shows Filepicker dialog and uploads the chosen file to the given url
*
* @param url URL where the file is sent
* @param successHandler Success callback function
* @param errorHandler Error callback function
* @see https://developer.mozilla.org/en-US/docs/Web/API/FormData
*/
function uploadFile(url, successHandler, progressHandler, errorHandler) {
var $fileInput = $('<input type=file>');
@nickrussler
nickrussler / gist:7527851
Created November 18, 2013 13:39
Convert Date String to/from ISO 8601 respecting UTC in Java
public static String toISO8601UTC(Date date) {
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
df.setTimeZone(tz);
return df.format(date);
}
public static Date fromISO8601UTC(String dateStr) {
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");