Skip to content

Instantly share code, notes, and snippets.

@hacst
hacst / hibp.py
Created January 17, 2019 20:24
Small python console script to check whether your password has been leaked to https://haveibeenpwned.com/ . See https://haveibeenpwned.com/API/v2#SearchingPwnedPasswordsByRange on why this is safe to do and you aren't leaking your password by checking.
#!/usr/bin/env python3
from hashlib import sha1
from getpass import getpass
from requests import get
def is_pwd_pwned(pwd):
""" Returns tuple of (pwned:boolean, occurances) for given password"""
h = sha1(pwd.encode('utf-8')).hexdigest().upper().encode('ascii')
prefix_h = h[:5]
suffix_h = h[5:]
@hacst
hacst / byk8xx.cpp
Created November 24, 2018 10:06 — forked from castleberrysam/byk8xx.cpp
Some reverse engineered C++ code from the BYK8xx firmware update utility
#include <stdio.h>
extern char *fw_data;
extern int fw_len;
// used to hold the RunOnlyOneUpdateTools mutex
extern HANDLE dword_458908;
// used to hold the first byte pair after the firmware header
extern int dword_45868c;
@hacst
hacst / pinout.txt
Created November 24, 2018 10:06 — forked from castleberrysam/pinout.txt
GPIO connections for BYK870 based keyboards (WIP)
rows and column numbers start at the bottom left
P0.2: USB pin D+
P0.3: USB pin D-
P0.4: USB pin D+ pulldown (used during reset)
P2.0: USB pin D- pullup (used during reset)
P0.5: switch row 6 drive
P0.6: switch row 5 drive
P0.7: switch row 4 drive
@hacst
hacst / CMakeLists.txt
Created June 5, 2018 23:18
Basic Systemd sd_notify + watchdog usage
cmake_minimum_required(VERSION 2.8)
project(sdnotify)
add_executable(sdnotify sdnotify.cpp)
target_link_libraries(sdnotify PUBLIC systemd)
@hacst
hacst / enum_class_generation_issue.i
Created July 15, 2015 21:34
Basic test case for SWIG code generation producing valid code not accepted by MSVC
%module EnumClassGenerationIssue
%include <std_vector.i>
%inline {
enum class TestEnum {};
}
%template(TestEnumVector) std::vector<TestEnum>;
@hacst
hacst / line-canvas-test.html
Last active August 29, 2015 14:14
Test Canvas based animation of a signal on a line
<html>
<style>
body {
}
#canvas {
width: 100%;
height: 100%;
margin: 0px;
}
@hacst
hacst / line-dasharray-test.html
Created January 23, 2015 16:29
Tests animation of a signal on a line using paths with stroke-dasharray
<html>
<style>
.line {
stroke: black;
fill: none;
stroke-width: 2px;
}
.signal {
stroke: red;
@hacst
hacst / crash.c
Last active August 29, 2015 14:10 — forked from mkrautz/crash.c
// Build x64 version with "cl -O2 /fp:fast crash.c"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
struct TonalityAnalysis {
int count[2]; //< Remove this or change it to multiples of 4 and it works
float std[4];
};
@hacst
hacst / gist:2b047b19e2eb7b053610
Created October 2, 2014 20:27
MetaParams::typeCheckedFromSettings specialization for size_t in case I end up needing it one day (Mumble code)
template <>
size_t MetaParams::typeCheckedFromSettings(const QString &name, const size_t &defaultValue) {
QVariant cfgVariable = qsSettings->value(name, defaultValue);
bool ok = false;
qulonglong value = cfgVariable.toULongLong(ok);
if (!ok || value > std::numeric_limits<size_t>::max()) {
qCritical() << "Configuration variable" << name << "is of invalid format. Set to default value of" << defaultValue << ".";
return defaultValue;
}
@hacst
hacst / main.cpp
Created May 25, 2013 19:44
Experimentation with typesafe indices for https://plus.google.com/u/0/103771295878903986513/posts/CiwQXgwHbJ1 Basically the gist of what I wanted from a strongly typedef'd size_t. This example only implements the operators I needed and already took quite a bit of code that might (will ;) ) contain bugs and unexpected behavior. For my application…
#include <vector>
#include <cstddef>
template<typename Tag>
class TypesafeIndex
{
public:
inline TypesafeIndex() : m_i() {};
inline explicit TypesafeIndex(const size_t a_value) : m_i(a_value) {};