Skip to content

Instantly share code, notes, and snippets.

@johntopley
johntopley / user.rb
Last active June 25, 2016 10:23
Ruby User class for Sinatra authentication scheme
# See comments for https://sideprojectsoftware.com/blog/2015/02/22/sinatra-authentication
require 'bcrypt'
require_relative 'database'
class User
include BCrypt
attr_reader :name
attr_reader :last_signin
@johntopley
johntopley / database.rb
Last active June 25, 2016 10:24
Ruby Database class for Sinatra authentication scheme
# See comments for https://sideprojectsoftware.com/blog/2015/02/22/sinatra-authentication
require 'mysql2'
class Database
def initialize(config = {})
@connection = Mysql2::Client.new(config['database'])
@connection.query_options.merge!(symbolize_keys: true)
end
@johntopley
johntopley / user_schema.sql
Last active June 25, 2016 10:23
MySQL users table for Sinatra authentication scheme
-- See comments for https://sideprojectsoftware.com/blog/2015/02/22/sinatra-authentication
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(255) NOT NULL default '',
`password_hash` varchar(255) NOT NULL default '',
`last_signin` timestamp NOT NULL default current_timestamp,
PRIMARY KEY (`id`),
UNIQUE KEY `username_index` (`username`)

Keybase proof

I hereby claim:

  • I am johntopley on github.
  • I am johntopley (https://keybase.io/johntopley) on keybase.
  • I have a public key whose fingerprint is A4BC BD01 B761 E247 376F DDEB 38C8 9216 191D ECC0

To claim this, I am signing this object:

@johntopley
johntopley / gist:034c960b8739ae65614e
Created July 2, 2014 19:01
Splunk-Friendly Apache Combined Log Format
LogFormat "remote_host=%h, remote_logname=%l, remote_user=%u, time=%t, request=\"%r\", status=%>s, bytes=%b, referer=\"%{Referer}i\", user_agent=\"%{User-agent}i\"" splunk_combined
@johntopley
johntopley / Xcode Increment Build
Created May 10, 2014 14:48
Xcode Run Script Build Phase to increment the build number
#!/bin/bash
build=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
build=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $build" "$INFOPLIST_FILE"
@johntopley
johntopley / Xcode Build in Numerous
Created May 10, 2014 14:45
Xcode Run Script Build Phase to update Numerous with current build number
#!/bin/bash
build=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
curl --user {userId}:"" --include --request POST --header "Content-Type: application/json" --data-binary "{\"value\":$build}" https://api.numerousapp.com/v1/metrics/{metricId}/events
map.resource :session, :controller => 'session',
:only => [:new, :create, :destroy],
:requirements => { :protocol => ssl_protocol }
class HelloWorld
def call(env)
[200, { 'Content-Type' => 'text/html' }, 'Hello Rack!']
end
end
java.util.Date dateUpdated = new Date(rset.getTimestamp("DateUpdated").getTime());