Skip to content

Instantly share code, notes, and snippets.

View trevorturk's full-sized avatar

Trevor Turk trevorturk

  • Chicago
View GitHub Profile
@trevorturk
trevorturk / 1.md
Last active September 11, 2023 20:29
Converting from a hash-of-arrays into an array-of-hashes

Most weather data sources give you an array of hashes (representing hours or days) with data points like so:

[
  {
    temperature: 73,
    windSpeed: 10,
  },
  {
 temperature: 70,
@trevorturk
trevorturk / gist:216549
Created October 23, 2009 02:10
nginx init.d
We couldn’t find that file to show.
@trevorturk
trevorturk / gists.rb
Created February 14, 2013 18:48
Delete all private gists
# gem install httparty
# ruby gists.rb
require 'httparty'
class Gists
include HTTParty
@username = 'x'
@password = 'x'
@trevorturk
trevorturk / main.rb
Created February 10, 2022 18:31 — forked from amirrajan/main.rb
DragonRuby Game Toolkit - Shadows (https://amirrajan.itch.io/shadows)
class Game
attr_gtk
def tick
defaults
input
calc
render
end
@trevorturk
trevorturk / gist:1756760
Created February 7, 2012 02:37
Bare minimum html5 template
<!DOCTYPE html>
<html>
<head>
<title>title</title>
</head>
<body>
<p>body</p>
</body>
</html>
@trevorturk
trevorturk / emoji.txt
Created April 3, 2012 18:47 — forked from stephencelis/emoji.txt
Emoji not on the iOS Keyboard
2139 ℹ INFORMATION SOURCE
23EB ⏫ BLACK UP-POINTING DOUBLE TRIANGLE
23EC ⏬ BLACK DOWN-POINTING DOUBLE TRIANGLE
23F0 ⏰ ALARM CLOCK
23F3 ⏳ HOURGLASS WITH FLOWING SAND
26C5 ⛅ SUN BEHIND CLOUD
26D4 ⛔ NO ENTRY
2705 ✅ WHITE HEAVY CHECK MARK
2753 ❓ BLACK QUESTION MARK ORNAMENT
2757 ❗ HEAVY EXCLAMATION MARK SYMBOL
# When a spammer wants to attack your site, they'll likely send an automated bot
# that will blindly fill out any forms it encounters. The idea of a "honeypot" is that
# you place a hidden field in a form. That's the honeypot. If this field is filled in, then
# it's almost certain to be a spammer (since a normal user wouldn't have even seen the
# field), and the contents of the form can safely be discarded.
# Normally, you would implement a "honeypot" in a Rails app with some combination of a
# special field in a particular form, and then some logic in the corresponding controller that
# would check for content in the "honeypot" field. This is somewhat of an inefficient
# approach, because it requires special code (not DRY), and bots are still going through an
@trevorturk
trevorturk / no_www.rb
Created November 3, 2009 05:03
no-www rack middleware
class NoWWW
STARTS_WITH_WWW = /^www\./i
def initialize(app)
@app = app
end
def call(env)
if env['HTTP_HOST'] =~ STARTS_WITH_WWW
@trevorturk
trevorturk / hello_world.rb
Created January 12, 2017 16:34
Single page Rails 5 app
# gem install bundler
# ruby hello_world.rb
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'rails', '~> 5.0'
end
$('.submittable').live('change', function() {
$(this).parents('form:first').submit();
});