This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ "keys": ["super+left"], "command": "prev_view" }, | |
{ "keys": ["super+right"], "command": "next_view" } | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from https://developers.google.com/appengine/docs/python/ndb/async | |
@ndb.tasklet | |
def get_cart_async(acct): | |
cart = yield CartItem.query(CartItem.account == acct.key).fetch_async() | |
yield ndb.get_multi_async([item.inventory for item in cart]) | |
raise ndb.Return(cart) | |
@ndb.tasklet | |
def get_offers_async(acct): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.appengine.ext import ndb | |
def tasklet(func): | |
"""Tasklet decorator that lets the caller specify either async or sync | |
behavior at runtime. | |
If make_sync is False (the default), the tasklet returns a future and | |
can be used in asynchronous control flow from within other tasklets | |
(like ndb.tasklet). If make_sync is True, the tasklet will wait for its | |
results and return them, allowing you to call the tasklet from synchronous |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.appengine.ext import db, ndb | |
from google.appengine.datastore import entity_pb | |
def db_entity_to_protobuf(e): | |
return db.model_to_protobuf(e).Encode() | |
def protobuf_to_db_entity(pb): | |
# precondition: model class must be imported | |
return db.model_from_protobuf(entity_pb.EntityProto(pb)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.appengine.ext import ndb | |
class ReferenceProperty(ndb.KeyProperty): | |
def _validate(self, value): | |
if not isinstance(value, ndb.Model): | |
raise TypeError('expected an ndb.Model, got %s' % repr(value)) | |
def _to_base_type(self, value): | |
return value.key |