Skip to content

Instantly share code, notes, and snippets.

View nphyx's full-sized avatar

Justen Robertson nphyx

View GitHub Profile
@nphyx
nphyx / gist:c911598aa1aa4071c34b9fe5c959d763
Created August 21, 2021 08:02
AU lbry-app-bin 0.51.1 > 0.51.2
commit fdf95587884d38743234a4ff227ac608cb40e5e8
Author: Justen Robertson <justen@justen.us>
Date: Sat Aug 21 00:56:56 2021 -0700
[UPDATE] 0.51.2
diff --git a/PKGBUILD b/PKGBUILD
index 8784e1f..6a09041 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@nphyx
nphyx / transmission_bind
Last active December 23, 2019 03:43
Update transmission bind address & peer port for Private Internet Access
#!/bin/bash
# Transmission address binding & port configurator for transmission-gtk (does not apply to transmission daemon)
#
# This script relies on my other script, piaport: https://gist.github.com/nphyx/e24c5349469f8dbca627761fafd57fbe
# It also requires gawk, and assumes it's in /usr/bin/gawk. If it's somewhere else for you change it.
#
# It must be run manually whenever VPN goes down and up again.
#
# You should already have bind-address-ipv4 and bind-address-ipv6 configured in your transmission settings.json!
#
@nphyx
nphyx / piaport
Last active December 23, 2019 03:23
Script to get a peer port for Private Internet Access
#! /bin/bash
#
# Enable port forwarding
#
# Based on another script found somewhere else, but this one gets user/pass automatically and requires sudo.
#
# Usage:
# $ sudo piaport
port_forward_assignment( )
@nphyx
nphyx / 60fps.rs
Last active February 5, 2024 00:45
Simple FPS Limit in Rust/Vulkano
// I don't know if this is the "right" way to do this, or even a "not stupid" way to do this, but I couldn't
// find an idiomatic approach and I'm a noob at Vulkan and graphics programming in general, so I came up with this
// the only reason it was difficult is that I first had to learn how Rust likes doing timing, using Duration and Instant
// rather than just using a ms/ns timestamp integer as one might expect
fn main() {
// [...] all your vulkan initialization stuff
// this is the target FPS
let fps = 60u32;
// set up a Duration representing the frame interval
@nphyx
nphyx / arraybuffer.transfer.js
Last active May 11, 2021 03:16
A polyfill for ArrayBuffer.prototype.transfer that is substantially faster than a naive byte-by-byte transfer implementation.
if(typeof(ArrayBuffer.prototype.transfer) === "undefined") {
ArrayBuffer.prototype.transfer = function transfer(old) {
var dva, dvb, i, mod;
dva = new DataView(this);
dvb = new DataView(old);
mod = this.byteLength%8+1;
for(i = 0; i <= old.byteLength-mod; i+=8) dva.setFloat64(i, dvb.getFloat64(i));
mod = this.byteLength%4+1;
if(i < old.byteLength-mod) {
dva.setUint32(i, dvb.getUint32(i));
@nphyx
nphyx / .zshrc
Created March 15, 2016 03:30
zsh bullet-train using terminal colors instead of fixed blue/white scheme
# Only directory, time & git are covered here
BULLETTRAIN_TIME_BG=000
BULLETTRAIN_TIME_FG=008
BULLETTRAIN_DIR_BG=001
BULLETTRAIN_DIR_FG=007
BULLETTRAIN_GIT_BG=000
BULLETTRAIN_GIT_FG=008
BULLETTRAIN_GIT_COLORIZE_DIRTY_BG_COLOR=000
BULLETTRAIN_GIT_MODIFIED=" %F{006}✹%F{black}"
@nphyx
nphyx / gist:73a2768e6b58e7bca5fa
Created March 15, 2016 03:29
zsh bullet-train using terminal colors
# BULLET-TRAIN CONFIG
BULLETTRAIN_TIME_BG=000
BULLETTRAIN_TIME_FG=008
BULLETTRAIN_DIR_BG=001
BULLETTRAIN_DIR_FG=007
BULLETTRAIN_GIT_BG=000
BULLETTRAIN_GIT_FG=008
BULLETTRAIN_GIT_COLORIZE_DIRTY_BG_COLOR=000
BULLETTRAIN_GIT_MODIFIED=" %F{006}✹%F{black}"
@nphyx
nphyx / should.nearly.js
Created February 28, 2016 17:24
A simple should.js extension for testing approximate values for array-like things. Works like approximately, but with arrays. Usage: [9.3567, 1.23456, 1.11112].should.be.nearly([9.36, 1.24, 1.12], 0.01);
const should = require("should");
should.Assertion.add("nearly", function(arr, delta) {
try {
for(let i = 0, len = arr.length; i < len; i++) {
this.obj[i].should.be.approximately(arr[i], delta);
}
}
catch(e) {
throw new Error("expected ["+this.obj.toString()+"] to be approximately ["+arr.toString()+"] ± "+delta);
}
@nphyx
nphyx / test-DataView_Uint42Accessors.js
Created September 14, 2015 06:27
Unit test for unsigned 24-bit int accessors for Javascript DataViews.
describe("DataView", function() {
it("should implement Uint24 accessors", function() {
var i, n, buf, dv;
buf = new ArrayBuffer(3);
dv = new DataView(buf);
n = Math.pow(2, 24);
// this should give us decent coverage without trying every single number, which takes forever
for(i = 1; i < n; i += 111) {
dv.setUint24(0, i);
dv.getUint24(0).should.equal(i);
@nphyx
nphyx / DataView_Uint24Accessors.js
Created September 14, 2015 06:25
Accessors for unsigned 24-bit ints on Javascript DataViews
/**
* Provide a 24 bit int implementation for DataViews. Note this
* causes two reads/writes per call, meaning it's going to be
* around half as fast as the native implementations.
*/
DataView.prototype.getUint24 = function(pos) {
return (this.getUint16(pos) << 8) + this.getUint8(pos+2);
}
DataView.prototype.setUint24 = function(pos, val) {