Skip to content

Instantly share code, notes, and snippets.

View whalesalad's full-sized avatar
🖨️
PC LOAD LETTER

Michael Whalen whalesalad

🖨️
PC LOAD LETTER
View GitHub Profile
@whalesalad
whalesalad / gist:3187925
Created July 27, 2012 13:20
How Unsubscribe Should Work

The Ideal Unsubscribe Flow

  • User clicks unsubscribe link in an email
  • User is immediately unsubscribed.
  • A message is displayed letting the user know that they'll be dearly missed.
  • A button is visible letting the user undo their unsubscribe action, in case they made a mistake.

Things to Avoid

  • User clicks unsubscribe from email
@whalesalad
whalesalad / load_data.py
Created August 21, 2012 01:28
riak load_data for goog.csv
#!/usr/bin/env python
import riak, csv
client = riak.RiakClient()
bucket = client.bucket('goog')
quotes = list(csv.reader(open('goog.csv', 'rb'), delimiter=','))
header = quotes.pop(0)
total = len(quotes)
# Generated by resolvconf
search dc.dc.cox.net
nameserver 68.105.28.12
nameserver 68.105.29.12
nameserver 68.105.28.11
<?php
$selected = $this->getRequired('selected');
$urlBase = App::urlBase();
$menuDataList = array(
'intro' => array(
'href' => $urlBase.'/about/intro',
'label' => 'Introduction',
@whalesalad
whalesalad / gist:4107851
Created November 18, 2012 22:21
My Sublime Text 2 Preferences
{
"auto_complete_commit_on_tab": true,
"bold_folder_labels": true,
"color_scheme": "Packages/User/Made of Code.tmTheme",
"font_size": 12.0,
"font_face": "Menlo",
"gutter": true,
"highlight_line": true,
"hot_exit": false,
"remember_open_files": false,
@whalesalad
whalesalad / gist:4276756
Created December 13, 2012 14:38
Another code-of-the-day snippet! This one will make your eyes bleed.
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
response.setContentType("text/plain");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
ActionStatus jObject = new ActionStatus();
@whalesalad
whalesalad / user.rb
Created January 12, 2013 17:46
A simple method to determine the interests that you have in common with another user.
# I love Object#tap
def interests_matching_with(another_user)
common_interests = (interests.pluck(:id) & another_user.interests.pluck(:id))
interests.map do |interest|
interest.tap { |n| n.matched = common_interests.include?(n.id) }
end
end
comet.dbld8.com: Started POST "/me/photo" for 95.199.135.109 at 2013-02-27 08:18:52 +0000
comet.dbld8.com: Processing by UserPhotoController#create as */*
comet.dbld8.com: Parameters: {"image"=>#<ActionDispatch::Http::UploadedFile:0x93b0584 @original_filename="image.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"image\"; filename=\"image.png\"\r\nContent-Type: image/png\r\n", @tempfile=#<File:/tmp/RackMultipart20130227-18265-1l5f2rn>>}
comet.dbld8.com: Completed 500 Internal Server Error in 293ms
@whalesalad
whalesalad / backup_database.rake
Last active December 16, 2015 23:59
This is a handy little rake script I created for dealing with database backups. It currently does two things: First, it provides a pg:backup task to dump the current DB and throw it onto S3. This can be run from anywhere, but I have it hooked into a cron task on my primary app server to do a backup of our production DB every few hours. Second, i…
require 'fog'
require 'socket'
namespace :pg do
def fog
@fog ||= Fog::Storage.new({
provider: Rails.configuration.fog['provider'],
aws_access_key_id: Rails.configuration.fog["aws_access_key_id"],
aws_secret_access_key: Rails.configuration.fog["aws_secret_access_key"]
})
@whalesalad
whalesalad / gist:5571730
Last active December 17, 2015 07:18
How to chain GPUImage filters together. Below is an example of doing a fast blur followed by a grayscale filter. The docs are a bit light on how to do this and a lot of folks seem to have a hard time. Below is an example that worked for me.
- (UIImage*)blurImage
{
// Create our sourcePicture for processing
GPUImagePicture *sourcePicture = [[[GPUImagePicture alloc] initWithImage:self] autorelease];
// init the fast blur filter
GPUImageFastBlurFilter *blurFilter = [[[GPUImageFastBlurFilter alloc] init] autorelease];
// set some parameters for the fast blur
[blurFilter setBlurPasses:3.0f];