Skip to content

Instantly share code, notes, and snippets.

View dylanvee's full-sized avatar

Dylan Vassallo dylanvee

  • San Francisco, CA
  • 20:10 (UTC -08:00)
View GitHub Profile
@dylanvee
dylanvee / gist:3419976
Created August 21, 2012 22:22
imagemagick crop square
# This snippet does everything I've ever wanted out of imagemagick.
# Equivalent to cropping to min(width, height) by min(width, height) and resizing to N x N.
# See http://www.imagemagick.org/Usage/thumbnails/#cut
# If you're writing this in bash or zsh, don't forget to escape the ^ with a backslash
convert -resize 256x256^ -extent 256x256 in.png out.png
@dylanvee
dylanvee / jruby_mina_sshd_example.rb
Created October 3, 2012 05:58
JRuby + Apache MINA SSHD
# First, download a binary distribution from
# http://mina.apache.org/sshd/sshd-070.html
# and copy lib/*.jar to your cwd
# Load all the jar files
require 'java'
Dir['./*.jar'].each {|jar| require jar }
# Import some Java classes
java_import java.util.EnumSet
@dylanvee
dylanvee / jruby_mina_sshd_publickey_example.rb
Created October 3, 2012 06:11
JRuby + Apache Mina SSHD public key
require 'net/ssh'
class CustomPublickeyAuthenticator
include PublickeyAuthenticator
def authenticate(username, key, session)
key = String.from_java_bytes(key.getEncoded)
key = [OpenSSL::PKey::RSA.new(key).to_blob].pack('m0')
# The key is now a string
# Your public key authentication magic here
Sometimes you learn from Codecademy; sometimes you learn from real-life experience. Yesterday, Codecademy was offline for almost 24 hours. We want to apologize and explain what happened.
What happened?
At 1:09AM EST on Wednesday 2/13, we took Codecademy down to deal with a database migration issue we were facing. We tweeted about it at 1:30. Then we spent the next 24 hours behind the scenes to iron out the issue.
How did it happen?
Like most web applications, Codecademy stores its information — everything from your submissions in exercises to new accounts — in a database. We use a technology called MongoDB (by our friends at 10gen) to do this. Our databases have hundreds of millions of items in them and are growing larger by the second. We've been working to change the configuration of our databases so that we can migrate our data to new database structures, laying a solid foundation for future developments and features.
if (status == CL_BUILD_PROGRAM_FAILURE) {
// Determine the size of the log
size_t log_size;
clGetProgramBuildInfo(program, devices[0], CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size);
// Allocate memory for the log
char *log = (char *) malloc(log_size);
// Get the log
clGetProgramBuildInfo(program, devices[0], CL_PROGRAM_BUILD_LOG, log_size, log, NULL);
[
{ "keys": ["super+left"], "command": "prev_view" },
{ "keys": ["super+right"], "command": "next_view" }
]
var teaser = _.chain(data.stories)
.pluck("teaser")
.filter(function(t) { return t && t.length })
.shuffle()
.first()
.value();
var teaser = _.chain(data.stories)
.pluck("teaser")
.filter(function(t) { return !!t.length; })
.shuffle()
.first()
.value();
khan
khanacaste
khanacre
khanal
khanalbumin
khanamed
khanarial
khanarium
khanation
khanational
// promises is an array of jqXHRs or what have you
var deferreds = _.map(promises, function(promise) {
var deferred = $.Deferred();
promise.then(
function() {
deferred.resolve(true);
},
function() {
deferred.resolve(false);
}