Skip to content

Instantly share code, notes, and snippets.

View gbuesing's full-sized avatar

Geoff Buesing gbuesing

View GitHub Profile
@gbuesing
gbuesing / ad_hoc.rb
Created June 20, 2013 04:53
Rack::AdHoc
# Allows you to write one-off middleware directly in config.ru. Good for prototyping.
#
# Example:
#
# use Rack::AdHoc do |app, env|
# status, headers, body = app.call(env)
# headers['X-Foo'] = 'bar'
# [status, headers, body]
# end
#
// delare WKScriptMessageHandler as delegate
// add to WKWebViewConfiguration init:
configuration.userContentController.addScriptMessageHandler(self, name: "log")
// MARK: WKScriptMessageHandler
func userContentController(userContentController: WKUserContentController, didReceiveScriptMessage message: WKScriptMessage) {
if (message.name == "log") {
print(message.body)
}
// declare WKUIDelegate as a delegate for ApplicationController
lazy var session: TLSession = {
let session = TLSession(webViewConfiguration: self.webViewConfiguration)
session.delegate = self
session.webView.UIDelegate = self // add this
return session
}()
// MARK: WKUIDelegate
@gbuesing
gbuesing / neo4j_client.rb
Last active June 28, 2016 00:29
Neo4j Data Import Example
require 'rest-client'
require 'json'
module Neo4jClient
SERVER = 'http://neo4j:neo4j@localhost:7474'
def self.cypher query, params = {}
resp = RestClient.post("#{SERVER}/db/data/cypher", {query: query, params: params}.to_json, content_type: :json, accept: :json)
JSON.parse resp
end
@gbuesing
gbuesing / transloadit_blocking_assembly_runner.rb
Last active November 19, 2016 21:23
Transloadit blocking assembly runner
# Blocks until response received
# Designed to be run from a background job, not in request-response
# Usage:
# assembly = Transloadit::Rails::Engine.template :my_template
# response = TransloaditBlockingAssemblyRunner.run assembly
# results = response['results']
module TransloaditBlockingAssemblyRunner
class Error < StandardError; end
class TimeoutError < Error; end
class AssemblyError < Error; end
@gbuesing
gbuesing / copy_row.sql
Created June 8, 2017 14:16
Copy single row from one Postgres DB into another via psql
# database 1
# output single row in format compatible with INSERT VALUES
\copy (SELECT * FROM users WHERE email = 'me@example.com') To stdout With CSV force quote * null 'NULL' quote ''''
# database 2
# insert values outputted from above command into another database
INSERT INTO users VALUES (...);

Keybase proof

I hereby claim:

  • I am gbuesing on github.
  • I am gbuesing (https://keybase.io/gbuesing) on keybase.
  • I have a public key ASC44xkHYLkEbRYoSApMVLq2Bxr2c0PxWMbVVszNNqiFmwo

To claim this, I am signing this object:

@gbuesing
gbuesing / Gemfile
Last active October 28, 2020 16:01
ActiveJob with resque-scheduler on Heroku
gem 'resque-scheduler'
@gbuesing
gbuesing / btclearcache.sh
Created September 20, 2014 03:39
Clear the Bluetooth attributes cache on Mac OS X
#!/bin/sh
# Clear the Bluetooth attributes cache on Mac OS X
# From http://expertsoverflow.com/questions/23549859/clearing-corebluetooth-gatt-cache-without-removing-bond
sudo defaults write /Library/Preferences/com.apple.Bluetooth CoreBluetoothCache -dict
sudo launchctl unload /System/Library/LaunchDaemons/com.apple.blued.plist
sudo launchctl load /System/Library/LaunchDaemons/com.apple.blued.plist
Map attributes from the open meteo forecast api to the format used by the Dark Sky API
The Open Meteo Forecast API and the Dark Sky API have different attribute names and structures, so mapping the attributes from one API to another requires some translation. Here's a list of Open Meteo Forecast API attributes and their corresponding Dark Sky API attributes:
Temperature
Open Meteo Forecast API: "temp"
Dark Sky API: "temperature"
Minimum temperature
Open Meteo Forecast API: "temp_min"
Dark Sky API: "temperatureMin"
Maximum temperature