Skip to content

Instantly share code, notes, and snippets.

View benschwarz's full-sized avatar
🏁
Making the web fast

Ben Schwarz benschwarz

🏁
Making the web fast
View GitHub Profile
" http://gist.github.com/gists/412549
"
" Paste syntax highlighted code into Keynote for presentational yum.
" by Lachie Cox
"
" put all this into your .vimrc
" (I might wrap it into a plugin one day)
"
" You could probably do the whole thing from vim, but I wanted to tweak to HTML
" a bit before pasting, so I pass the HTML to a ruby script (Gisted below)
<ul>
<% User.all.with_item_counts do |user| %>
<li><%= user.username %> - Items: <%= user.calculated_item_count %>
<% end %>
</ul>
@masterkain
masterkain / lastfm.rb
Created May 27, 2011 22:20 — forked from lucasmazza/lastfm.rb
a Last.FM Strategy for OmniAuth
require 'omniauth/core'
require 'digest/md5'
require 'rest-client'
require 'multi_json'
module OmniAuth
module Strategies
class Lastfm
include OmniAuth::Strategy
@tlrobinson
tlrobinson / test.js
Created June 19, 2011 05:52
Implementations of parallel and serial "map" function for Q lib
function mapParallel(array, callback) {
return array.reduce(function(acc_p, element, index, array) {
return Q.when(callback(element, index, array), function(res) {
return Q.when(acc_p, function(acc) {
return acc.concat([res]);
});
});
}, []);
}
@madrobby
madrobby / gist:3202087
Created July 29, 2012 22:01
Fallback to PNG if SVG is not supported
<!-- example for the http://retinafy.me ebook -->
<style>
div.rss {
background: url(rss.svg);
width: 32px;
height: 32px;
}
body.no-svg div.rss {
# First configure your models to use Amazon s3 as storage option and setup the associated S3 config.
# Then add the classes your want to migrate in the klasses array below.
# Then run rake paperclip_migration:migrate_to_s3
# Should work but this is untested and may need some tweaking - but it did the job for me.
namespace :paperclip_migration do
desc "migrate files from filesystem to s3"
task :migrate_to_s3 => :environment do
klasses = [:product] # Replace with your real model names. If anyone wants to this could be picked up from args or from configuration.
klasses.each do |klass_key|
@tanguyantoine
tanguyantoine / foo_type.rb
Created August 19, 2017 18:01
New Relic GraphQL Ruby instrumentation
Types::FoosType = GraphQL::ObjectType.define do
field :foos, !types[Types::FooType] do
timed true # enable New Relic trace_execution_scoped
description "Returns foos"
argument :per, types.Int, default_value: 20
argument :page, types.Int, default_value: 1
# Moving to cursor pagination would be better
resolve(...)
end
end
@kagemusha
kagemusha / gist:1569836
Created January 6, 2012 09:20
Dump Heroku Postgres DB and load locally
Get the Heroku db as detailed here:
http://devcenter.heroku.com/articles/pgbackups#exporting_via_a_backup
1. heroku pgbackups:capture
2. heroku pgbackups:url <backup_num> #=>backup_url
- get backup_num with cmd "heroku pgbackups"
3. curl -o latest.dump <backup_url>
Then locally do:
$ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump
@bradland
bradland / ssh-known-hosts-mgmt.sh
Last active April 4, 2023 21:21
SSH known_hosts tools
# This is a short collection of tools that are useful for managing your
# known_hosts file. In this case, I'm using the '-f' flag to specify the
# global known_hosts file because I'll be adding many deploy users on this
# system. Simply omit the -f flag to operate on ~/.ssh/known_hosts
# Add entry for host
ssh-keyscan -H github.com >> /etc/ssh/ssh_known_hosts
# Scan known hosts
ssh-keygen -f /etc/ssh/ssh_known_hosts -F github.com
@datagrok
datagrok / git-serve.md
Last active April 21, 2023 07:33
How to easily launch a temporary one-off git server from any local repository, to enable a peer-to-peer git workflow.