Skip to content

Instantly share code, notes, and snippets.

Jørgen P. Tjernø jorgenpt

View GitHub Profile
View steam_transaction_totals.js
// To be run on https://store.steampowered.com/account/history/
function parseTotals()
{
var transactions = document.getElementsByClassName('wallet_table_row');
var totals = { usd: 0, eur: 0 };
for (var i = 0; i < transactions.length; ++i)
{
var transaction = transactions[i];
var items = transaction.getElementsByClassName('wht_items')[0];
if (items && items.innerText.indexOf('Wallet Credit') >= 0)
@jorgenpt
jorgenpt / TextProgressBar.cs
Last active Apr 2, 2020
Text based progress bar for C#
View TextProgressBar.cs
using System;
using System.Collections.Generic;
namespace JPT
{
public class TextProgressBar : IDisposable
{
private int _progress;
private int _total;
private int _width;
@jorgenpt
jorgenpt / extract_runtime.sh
Created May 26, 2014
Helper scripts to update & extract the steam-runtime for direct distribution.
View extract_runtime.sh
#!/bin/bash -e
# Helper script for extracting the steam-runtime that:
# - Strips unused parts of the runtime (documentation)
# - Allows you to extract a single architecture
# - Extracts it to a directory that doesn't contain the runtime date.
function fatal() { echo "$@" >&2; exit 1; }
if [ $# -lt 3 ]; then
fatal "Usage: $0 <steam-runtime path> <amd64|i386|all> <output directory>" >&2
@jorgenpt
jorgenpt / wrapper.sh
Last active Aug 29, 2015
steam-runtime launcher script for use outside of Steam
View wrapper.sh
#!/bin/bash
# Path relative to the directory where the executable lives.
JPT_STEAM_RUNTIME_LOCATION='steam-runtime'
# Figure out where this script lives.
exedir="$(cd "$(dirname "$0")" && pwd)"
# If this script is named `foo.sh' or `foo', we execute `foo.bin'
exename="$(basename "$0" ".sh").bin"
@jorgenpt
jorgenpt / SaneMinMaxMacros.h
Last active Mar 17, 2020
An attempt at some saner min-max-clamp macros for C and Objective-C. Require a modern compiler (C11) with support for statement expressions (Gnu11).
View SaneMinMaxMacros.h
#pragma once
#define _CheckTypes(a,b) _Static_assert(_Generic(a, typeof (b):1, default: 0), "Mismatched types")
#define Min(a,b) \
({ \
const typeof (a) _a = (a); \
const typeof (b) _b = (b); \
_CheckTypes(_a,_b); \
(_a < _b ? _a : _b); \
View keybase.md

Keybase proof

I hereby claim:

  • I am jorgenpt on github.
  • I am jorgenpt (https://keybase.io/jorgenpt) on keybase.
  • I have a public key whose fingerprint is C54B EFD5 C4CF 4AEE D568 9A3C CEE2 5916 07D6 4BF0

To claim this, I am signing this object:

@jorgenpt
jorgenpt / ksdiff-batch.sh
Last active Oct 9, 2019
Batches multiple invocations of ksdiff to open in a single Kaleidoscope window if they happen within a few seconds of eachother. This is useful for Kaleidoscope integration with P4V, since it makes a multi-file diff open in a single window. If it doesn't quite pick up all your files, try setting TIMEOUT to more than 4 seconds.
View ksdiff-batch.sh
#!/bin/bash
# Number of seconds we wait after a file is received before we consider the
# batch to be completed.
TIMEOUT=2
# Title of the tab in Kaleidoscope
LABEL="P4V ksdiff-batch"
# FIFO we communicate with the "batch master" for.
fifo="/tmp/ksdiff-batch-$USER"
View RunHammerwatch
#!/bin/bash
DIR=$(cd "$(dirname "$0")"; pwd)
MONO=`which mono`
if [ ! -z "$MONO" ]; then
TXT=`${MONO} -V`
VERSION="${TXT#"${TXT%%[[:digit:]]*}"}"
VERSION="${VERSION%%[^[:digit:].]*}"
VERSION="${VERSION//[!0-9\.]/}"
fi
@jorgenpt
jorgenpt / HTTPSCertificateRetriever.h
Last active Dec 27, 2015
Utility class to retrieve HTTPS certificates from a server.
View HTTPSCertificateRetriever.h
#import <Foundation/Foundation.h>
@protocol HTTPSCertificateRetrieverDelegate <NSObject>
/**
* Called when we succeed (or fail) to retrieve the certificate.
*
* @param certificate nil if we fail, otherwise the data of the certificate.
*/
- (void)certificateRetrieved:(NSData*)certificate;
@jorgenpt
jorgenpt / gist:6589639
Created Sep 17, 2013
Remove the "Command-T" hotkey in Finder, which normally is "Add to Sidebar"
View gist:6589639
defaults write com.apple.finder NSUserKeyEquivalents -dict-add "Add to Sidebar" nil
You can’t perform that action at this time.