Skip to content

Instantly share code, notes, and snippets.

View skl's full-sized avatar

Stephen Lang skl

View GitHub Profile
/**
* Takes a property path array, p, and a value, v, and returns an object to that spec.
*
* Example:
* objectify( ['foo', 'bar', 'baz'], [1, "42", {answer: 42}] )
*
* Would return an object literal in the form:
* {
* foo: {
* bar: {
@skl
skl / PopSheet.swift
Created June 19, 2020 01:08
This is a workaround for iPad ActionSheets disappearing off the screen.
//
// PopSheet.swift
//
// Adapted from:
// https://stackoverflow.com/questions/56910941/present-actionsheet-in-swiftui-on-ipad
//
import SwiftUI
extension View {
@skl
skl / iosProximityObserver.swift
Created May 29, 2020 11:49
iOS SwiftUI proximity observer example
import SwiftUI
import UIKit
class ProximityObserver {
@objc func didChange(notification: NSNotification) {
print("MyView::ProximityObserver.didChange")
if let device = notification.object as? UIDevice {
print(device.proximityState)
}
}
#!/bin/bash
set -e
if [ "Darwin" != $(uname) ]; then
echo "This script is currently only compatible with macOS"
exit 1
fi
cd $HOME
curl https://gist.githubusercontent.com/skl/4dcf37c08a2c323c44e717840a8b4316/raw/226785983c0670e9bde5a7b5b311df04d57b6e2d/repair-sqlite-db.sh > repair-sqlite-db
@skl
skl / repair-sqlite-db.sh
Last active December 2, 2022 14:39
Repair SQLite DB [macOS]
#!/bin/bash
set -e
function ph_is_installed() {
command -v $1 > /dev/null 2>&1 && return 0 || return 1
}
if ! ph_is_installed sqlite3; then
if [ "Darwin" != $(uname) ]; then
echo "This script is currently only compatible with macOS"
@skl
skl / install-jupyter-pdf-deps.sh
Created August 13, 2019 12:30
Jupyter Notebook Print to PDF on macOS
brew install pandoc homebrew/cask/basictex
# Add following to .bashrc or .zshrc for example
export PATH=/Library/TeX/texbin/:$PATH
# Use TeX Live Manager to install required packages missing from basictex
sudo tlmgr update --self && sudo tlmgr install tcolorbox environ trimspaces adjustbox collectbox ucs titling enumitem collection-fontsrecommended
{
"basic": {
"license key": "***REMOVED SENSITIVE VALUE***",
"date": "Thu, 22 Feb 2018 09:44:27 +0000",
"ownCloud version": "10.0.7.2",
"ownCloud version string": "10.0.7",
"ownCloud edition": "Community",
"server OS": "Linux",
"server OS version": "Linux ***REMOVED SENSITIVE VALUE*** 4.4.38-std-1 #1 SMP Mon Dec 12 10:45:29 UTC 2016 x86_64",
"server SAPI": "fpm-fcgi",
@skl
skl / hostapd
Last active May 12, 2017 13:51
Reliable hostapd init script - example with brcmfmac driver in GB region - See http://skl.me/#wifi-access-point-in-debian
#!/bin/sh
### BEGIN INIT INFO
# Provides: hostapd
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Should-Start: $network
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
@skl
skl / gist:10a32cf602ff9aee4043f0f4f4c66e66
Created September 10, 2016 16:11
ATmega 328P Internal Temperature Sensor on ADC8
; Initialise A/D multiplex register for internal temp. sensor (ADC8)
; Use internal (1.1V) as reference voltage and left-adjust
ADC_TempSensor_Init:
ldi r17, (1<<REFS1) | (1<<REFS0) | (1<<MUX3) | (1<<ADLAR)
sts ADMUX, r17 ; out of range for OUT, using STS instead
ret
; Reads ADCL into r21 and ADCH into r22
ADC_TempSensor_Read:
; Enable ADC with a clock division factor of 128 (125 kHz)
@skl
skl / Module.php
Created September 16, 2015 16:13
ZF2 ModuleEvent listener that prioritises `ViewJsonStrategy` over `ZfcTwigViewStrategy` in order to properly render a JsonModel.
<?php
namespace Application;
use Zend\ModuleManager\ModuleEvent;
use Zend\ModuleManager\ModuleManager;
/**
* Class Module
* @package Application