Skip to content

Instantly share code, notes, and snippets.

View aguynamedben's full-sized avatar

Ben Standefer aguynamedben

View GitHub Profile
@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,
@adeperio
adeperio / AuthService.js
Last active January 8, 2022 20:06
PKCE flow in Electron with Passwordless. In ES6 + flow + request-promise. Executes PKCE through the Electron BrowserWindow
//@flow
import request from 'request'
import crypto from 'crypto'
import rp from 'request-promise'
export type AuthServiceConfig = {
authorizeEndpoint: string,
clientId: string,
audience: string,
scope: string,
@vasanthk
vasanthk / System Design.md
Last active May 6, 2024 20:21
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@dropmeaword
dropmeaword / browser_history.md
Last active April 5, 2024 17:37
Playing around with Chrome's history

Browser histories

Unless you are using Safari on OSX, most browsers will have some kind of free plugin that you can use to export the browser's history. So that's probably the easiest way. The harder way, which seems to be what Safari wants is a bit more hacky but it will also work for other browsers. Turns out that most of them, including Safari, have their history saved in some kind of sqlite database file somewhere in your home directory.

The OSX Finder cheats a little bit and doesn't show us all the files that actually exist on our drive. It tries to protect us from ourselves by hiding some system and application-specific files. You can work around this by either using the terminal (my preferred method) or by using the Cmd+Shft+G in Finder.

Finder

Once you locate the file containing the browser's history, copy it to make a backup just in case we screw up.

@jspillers
jspillers / vcr_webmock_and_live_http_simultaneously.rb
Created June 9, 2015 20:13
Sandbox test to get VCR, WebMock, and "real" http all working side by side in the same spec suite
require 'rubygems'
require 'rspec'
require 'webmock'
require 'vcr'
require 'pry'
# in a Rails app, this would be in an initializer
WebMock.disable_net_connect!(
allow_localhost: true,
net_http_connect_on_start: true

Last updated: 2014-12-25

mdfind commands

Find all the file types in a given directory

mdfind -attr kMDItemContentType "kMDItemContentType == '*'" -onlyin . | awk -F"kMDItemContentType =" '{print $2}' | sort | uniq -c | sort -r

Get Last 5 Files Added in Dropbox Folders

@niyazpk
niyazpk / pQuery.js
Created October 25, 2014 14:03
Add or update query string parameter
// Add / Update a key-value pair in the URL query parameters
function updateUrlParameter(uri, key, value) {
// remove the hash part before operating on the uri
var i = uri.indexOf('#');
var hash = i === -1 ? '' : uri.substr(i);
uri = i === -1 ? uri : uri.substr(0, i);
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
@justecorruptio
justecorruptio / 2048.pl
Created April 9, 2014 08:39
Even smaller 2048 in Perl !!!
sub Y{$p=$_;for$i(1..4){$p=join'',map{substr+($k&&$k-$i?$p:join'',map{s/@//g;s
/(.)\1/++($a=$1)/eg;$_|'@'x4}$p=~/.{4}/g),3+$_%4*4-($_/4|0),1}0..15}$p}$_='@'x
16;for(`stty cbreak`;print"\e[2J\e[H";$_=Y map{$k=index+JDACB,getc}0..2){$k=0;
1until$r=0|rand 16,!/@/||s/(?<=^.{$r})@/rand>.1?A:B/e;printf'%4s|%s',/\w/&&1<<
(ord)-64,++$g%4?'':$/for/./g;last if$e=WIN x/K/||Y!~/@/&&LOSE}print$e # [2048]
@backflip
backflip / config.rb
Last active July 11, 2017 14:53
Using Redcarpet and Middleman Syntax for Markdown and HAML files
class CustomMarkdown < Middleman::Extension
$markdown_options = {
autolink: true,
fenced_code_blocks: true,
no_intra_emphasis: true,
strikethrough: true,
tables: true,
hard_wrap: true,
with_toc_data: true
}
@dvdplm
dvdplm / mock_tire.rb
Created March 27, 2012 11:06
Mocking helper to stop Tire from submitting searches to Elasticsearch
module Tire
module Disable
module ClassMethods
def mock_es_response_doc
@mock_es_response_doc ||=
'{"took": 1,"timed_out": false,"_shards": {"total": 5,"successful": 5,"failed": 0},"hits": {"total": 0,"max_score": null,"hits": []}}'
end
def enable! &blk
old_enabled = @tire_enabled || false