Skip to content

Instantly share code, notes, and snippets.

View aguynamedben's full-sized avatar

Ben Standefer aguynamedben

View GitHub Profile
@aguynamedben
aguynamedben / README.md
Last active December 9, 2021 09:15
Setting up SQLCipher with node-sqlite3 and Electron

Gist notes

How I got SQLCipher working with Electron on macOS:

  • First compile SQLCipher and dynamically link it to macOS' crypto libraries. Don't use OpenSSL. Zetetic (makers of SQLCipher) say that using macOS' crypto libraries is definitely going to be easiest on a Mac. Note that using SQLCipher libraries installed via Homebrew is going to seem like it works, and it will on your computer, but Homebrew's SQLCipher dynamcially links OpenSSL, so your app will crash when deployed to other computers (i.e. dynamic linking will fail at run timer because other computer wont have OpenSSL installed). So you want to dynamically link macOS crypto.
  • Then you want to rebuild node-sqlite3 with a modified binding.gyp so that the SQLCipher library is statically linked into your SQLite binding. You should end up with a binary file ./node_modules/sqlite3/lib/binding/electron-v3.0-darwin-x64/node_sqlite3.node that has libsqlcipher.a statically linked within it. The statically linked libsqlcipher.a will in-turn dynamically
@aguynamedben
aguynamedben / localStorage.js
Created August 25, 2020 16:32
Persist Redux to localStorage, with migrations (i.e. migrate off redux-persist)
// @flow
// Inspired by https://medium.com/@jrcreencia/persisting-redux-state-to-local-storage-f81eb0b90e7e
const log = console;
let firstLoad = true;
export function loadState() {
try {
const serializedState = localStorage.getItem('state');
if (!serializedState) {
@aguynamedben
aguynamedben / jsHelpers.js
Last active December 12, 2018 18:41
Get friendly OS values in Node.js
import log from 'electron-log';
import macosVersion from 'macos-version';
export function humanOSName() {
const platform = os.platform();
if (platform === 'darwin') {
return 'macOS';
} else if (platform === 'win') {
return 'Windows';
} else if (platform === 'linux') {
@aguynamedben
aguynamedben / custom-node-sqlite3-binding.gyp
Last active October 28, 2018 21:12
Rebuilding node-sqlite3 with support for statically linked SQLCipher
# This is a modified version of binding.gyp (from node-sqlite3) that allows
# SQLCipher to be *statically linked* for Electron distribution to machines that
# do not have SQLCipher development headers present. If you distribute
# node-sqlite3 with dynamically linked SQLite/SQLCipher bindings (the default),
# your app will error out at runtime on user's machines that do not have
# SQLCipher.
#
# This problem is tricky to test and catch because the app will work fine on
# your machine, because you've probably installed SQLCipher to custom-build
# node-sqlite3. To test that everything is working, package your Electron app,
### Keybase proof
I hereby claim:
* I am aguynamedben on github.
* I am aguynamedben (https://keybase.io/aguynamedben) on keybase.
* I have a public key ASDlkClWlN-6NYMMp05UIFdu-NMB3ZJ8_hC9UCl7_g0X4go
To claim this, I am signing this object:
@aguynamedben
aguynamedben / with 100k records
Last active March 7, 2018 09:08
search benchmarking
ip-192-168-7-30!ben:/Users/ben/code/fuzzracer$ yarn test
yarn run v1.5.1
$ mocha -r jsdom-global/register -r babel-core/register test/setup.js test/**/*.spec.js
Benchmarking IndexStore
100000 records created in 1871ms
Indexing took 4239ms
1000 queries created in 16ms
Quality check - Displaying 10 queries with top 10 results:
@aguynamedben
aguynamedben / gist:5341501
Last active December 15, 2015 23:39
How I use Gmail
Settings > General > Maximum Page Size > Show [100] conversations per page
Go to Inbox.
Click email in bottom (oldest).
Arrow keys to read.
Choose Option 1 or 2...
{
"private": true,
"annotations": {
"venue": {
"profitable": "yes",
"owner": "China Basin Ballpark Corp."
},
"building": {
"size": "extra small",
"material": "wood",
"weather": {
"cloud_cover": "80%",
"conditions": "Mostly cloudy",
"dewpoint": "47F",
"forecast": {
"today": {
"conditions": "Clear",
"precipitation": "20%",
"temperature": {
"max": "58F",
[alias]
a = add
br = branch
ci = commit
cl = clone
co = checkout
df = diff
lg = log -p
h = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
st = status