Skip to content

Instantly share code, notes, and snippets.

Avatar

Nathan Osman nathan-osman

View GitHub Profile
@nathan-osman
nathan-osman / main.go
Created March 9, 2021 04:34
Custom dialector to force sqlite driver in GORM to use "integer" type for booleans instead of "numeric".
View main.go
package main
import (
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/schema"
)
// CustomDialector allows for customization of the type affinity for booleans.
type CustomDialector struct {
@nathan-osman
nathan-osman / puzzle.py
Last active April 5, 2020 04:06
Calculate the answer to this puzzle: https://i.stack.imgur.com/4MMS7.jpg
View puzzle.py
# Build a list of all possible combinations
a = []
for i in range(0, 10):
for j in range(0, 10):
for k in range(0, 10):
a.append('{}{}{}'.format(i, j, k))
# For each of the possible answers, check the five constraints
for v in a:
pass_1 = \
@nathan-osman
nathan-osman / smsformat.py
Created April 1, 2020 05:53
Format XML files produced by SMS Backup & Restore
View smsformat.py
from argparse import ArgumentParser
from datetime import datetime, timezone
from html import escape
import xml.etree.ElementTree as ET
class SmsFormat:
def __init__(self, f_in, f_out):
@nathan-osman
nathan-osman / CMakeLists.txt
Last active March 19, 2022 23:43
Enumerate network interfaces and addresses assigned to them
View CMakeLists.txt
cmake_minimum_required(VERSION 3.2.0 FATAL_ERROR)
project(netenum)
find_package(Qt5Network 5.4 REQUIRED)
add_executable(netenum main.cpp)
target_link_libraries(netenum Qt5::Network)
@nathan-osman
nathan-osman / CMakeListst.txt
Created November 1, 2017 20:14
Write to STDOUT using QFile
View CMakeListst.txt
cmake_minimum_required(VERSION 3.2.0 FATAL_ERROR)
project(stdout)
find_package(Qt5Core 5.4 REQUIRED)
add_executable(stdout main.cpp)
target_link_libraries(stdout Qt5::Core)
@nathan-osman
nathan-osman / ppastats.py
Created July 14, 2017 16:56
Updated script for retrieving PPA download counts - https://askubuntu.com/a/296200/5
View ppastats.py
#!/usr/bin/env python2
from argparse import ArgumentParser
from sys import exit
try:
from launchpadlib.launchpad import Launchpad
from tabulate import tabulate
except ImportError:
print "python-launchpadlib and python-tabulate are required"
@nathan-osman
nathan-osman / button.png
Last active February 4, 2019 07:35
Android emulator skin for the OnePlus 3
@nathan-osman
nathan-osman / temperature.ino
Last active April 29, 2017 05:50
Measure temperature and humidity and display the values on an OLED screen.
View temperature.ino
/**
* Measure temperature & humidity and display on OLED screen
* Copyright 2017 - Nathan Osman
*/
#include <DHT.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSans12pt7b.h>
#define DHTPIN 3
@nathan-osman
nathan-osman / letsencrypt.go
Created April 20, 2017 02:22
Obtain a Let's Encrypt certificate from the ACME staging server using golang.org/x/crypto/acme
View letsencrypt.go
package main
import (
"context"
"crypto"
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
@nathan-osman
nathan-osman / measurer.ino
Created April 19, 2017 23:14
Measure distance and display on OLED screen
View measurer.ino
/**
* Measure distance and display on OLED screen
* Copyright 2017 - Nathan Osman
*/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSans12pt7b.h>