Skip to content

Instantly share code, notes, and snippets.

View matthewlehner's full-sized avatar
👻

Matthew Lehner matthewlehner

👻
View GitHub Profile
@matthewlehner
matthewlehner / application.rb
Created October 26, 2015 19:22
SystemJS config for sprockets-es6
config.assets.configure do |env|
env.register_transformer 'text/ecmascript-6',
'application/javascript',
Sprockets::ES6.new('modules' => 'system',
'moduleIds' => true)
end
@matthewlehner
matthewlehner / gist:16fbb3ee2fb7053e2ead
Created July 25, 2015 03:22 — forked from TattdCodeMonkey/gist:e08acb86343bc8e43866
Justin Weiss - Is Rails fast enough?

Is Rails fast enough?

When a new language or web framework pops up, what do you usually see along with it?

Benchmarks. Benchmarks like these.

As a Rails developer, you might be embarassed to see this. I mean, Rails is more than a full order of magnitude slower than Phoenix! And even Sinatra is about 3x faster.

But what do you do about stats like this? Do you shift to another language, so you can get faster response times? Do you move to a different architecture, with some services written in Go, some in Elixir, talking to a frontend in JavaScript? What would you even use Rails for, then?

require "net/http"
require "openssl"
uri = URI("https://github.com")
request = Net::HTTP.new(uri, 443)
request.use_ssl = true
request.ssl_version = :SSLv23
request.verify_mode = OpenSSL::SSL::VERIFY_NONE
request.get("/")
class ArraySerializer
def initialize(objects, *args)
@objects = objects
end
def to_json
serializable_array.to_json.html_safe
end
def serializable_array
@matthewlehner
matthewlehner / code formatter snippet.sh
Created March 26, 2014 08:07
RTF syntax highlighter for the command line
# brew install highlight
# then put your ugly code in the clipboard and run this :)
pbpaste | highlight --syntax=js --font-size 24 --font Monaco -O rtf --style solarized-light | pbcopy
@matthewlehner
matthewlehner / initializer.rb
Last active August 29, 2015 13:57
Rails Mail Interceptor
# config/initializers/sandbox_email_interceptor.rb
ActionMailer::Base.register_interceptor(SandboxEmailInterceptor) if Rails.env.development?
@matthewlehner
matthewlehner / sandbox_email_interceptor.rb
Created March 12, 2014 02:15
Rails Email Interceptor
ActionMailer::Base.register_interceptor(SandboxEmailInterceptor) if Rails.env.staging?
@matthewlehner
matthewlehner / heroku_pg_pull.sh
Last active January 4, 2016 10:49
zsh (maybe bash too?) scripts for pulling and pushing Heroku dbs
# Postgres equivalent to heroku db:pull.
# Pulls latest heroku pgbackups dump into local database
#
# Usage:
#
# $ heroku_pg_pull [appname] [local database name]
#
function heroku_pg_pull(){
echo "! WARNING: Data in the local database '$2' will be destroyed."
echo " Type '$2' to overwrite data in local database '$2'"
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.js"></script>
<script src="http://builds.emberjs.com/canary/ember.prod.js"></script>
</head>
def upload(filename, file_location)
bucket = AWS::S3::Bucket.new(ENV["AWS_BUCKET_NAME"])
key = "uploads/#{SecureRandom.uuid}/#{filename}"
content_type = MIME::Types.type_for(filename).first.to_s
presigned_post = bucket.presigned_post(key: key, content_type: content_type)
url = presigned_post.url.to_s
fields = presigned_post.fields
`curl -i -v -X POST -F "AWSAccessKeyId=#{fields['AWSAccessKeyId']}" -F "key=#{fields['key']}" -F "policy=#{fields['policy']}" -F "signature=#{fields['signature']}" -F "Content-Type=#{content_type}" -F "file=@#{file_location + filename}" '#{url}'`
end