Skip to content

Instantly share code, notes, and snippets.

Avatar
🌸
ヽ◕◡◕✿ノ

ヽ◕◡◕✿ノ farzher

🌸
ヽ◕◡◕✿ノ
View GitHub Profile
@farzher
farzher / myfloat.js
Last active Jun 27, 2020
floating precision positive whole numbers using arbitrary mantissa / exponent sizes
View myfloat.js
function tomyfloat(mbits, ebits, value) {
if(mbits + ebits > 31) throw new Error('no support for > 31 bits')
if(value < 0) throw new Error('no support for negative numbers')
if(Math.floor(value) !== value) throw new Error('no support for decimal numbers (lol)')
if(value >= (2**mbits-1)*2**(2**ebits-1)) return 2**(mbits+ebits)-1
const bitstr = value.toString(2)
const len = bitstr.length
let m = parseInt(bitstr.substr(0, mbits), 2)
let e = Math.min(2**ebits-1, Math.max(0, len - mbits))
if( (m < 2**mbits-1 || e < 2**ebits-1) && Math.abs(value - (m+1)*2**e) < Math.abs(value - m*2**e)) m++
@farzher
farzher / bitpacker.js
Last active Sep 18, 2020
for writing data to a compact custom binary format. serialize / save / send data over the network using the minimal amount of bits.
View bitpacker.js
function bitpacker(bytes=[]) {
return {
bytes: bytes,
bitcursor: 0,
write(bitcount, value) {
if(typeof value === 'string') value = value.charCodeAt(0)
else if(typeof value === 'boolean') value = value?1:0
else if(value > 2**bitcount-1) value = 2**bitcount-1 // overflow will stay at max value instead of wrapping
@farzher
farzher / fighter.ahk
Created May 16, 2013
Fighting Game Shortcuts
View fighter.ahk
#SingleInstance force
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Event ; Recommended for new scripts due to its superior speed and reliability.
SetTitleMatchMode RegEx
#MaxHotkeysPerInterval 1000
!F11::Suspend
; reload script
^!+s::
Reload
@farzher
farzher / colemak_developer.ahk
Last active Aug 30, 2017
Colemak For Developers
View colemak_developer.ahk
#SingleInstance force
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Event ; Recommended for new scripts due to its superior speed and reliability.
SetTitleMatchMode RegEx
#MaxHotkeysPerInterval 10000
; reload script
^!+s::Reload
; capslock is another escape
Capslock::Esc
You can’t perform that action at this time.