Skip to content

Instantly share code, notes, and snippets.

Avatar

Timothée Peignier cyberdelia

View GitHub Profile
@iconara
iconara / InputStreamResponseTransformer.java
Last active Nov 5, 2020
S3 GetObject InputStreamResponseTransformer using AWS SDK for Java v2
View InputStreamResponseTransformer.java
// this is an attempt to create a synchronous InputStream from a call to
// S3AsyncClient#getObject using a blocking queue.
//
// the purpose is to be able to make many S3 operations asynchronously, but
// at the same time be able to pass off some results to threads and into
// code that expects InputStream or Reader, like a Commons CSV.
public class InputStreamResponseTransformer extends InputStream implements AsyncResponseTransformer<GetObjectResponse, InputStream>, Subscriber<ByteBuffer> {
private static final ByteBuffer END_MARKER = ByteBuffer.allocate(0);
@ericflo
ericflo / undo.js
Last active Sep 15, 2016
Adds undo capabilities into your React.js component.
View undo.js
var UndoMixin = {
getInitialState: function() {
return {
undo: []
};
},
handleUndo: function() {
if (this.state.undo.length === 0) {
return;
@joestump
joestump / San_Francisco.mkd
Created Feb 1, 2014
Here are two tours of San Francisco and the surrounding area. Both take about a day. One is entirely within the city and can be done entirely via public transportation. The other requires a car and gets you outside of SF to some of the wonderful sites that comprise the Yay Area.
View San_Francisco.mkd

San Francisco by Foot

  • You can start anywhere in the Castro, Mission (home of the burrito), or downtown. I'd recommend starting at Chow at Market & Church or The Pork Store on 16th at Valencia. If you wanted to go upscale on the weekend, Maverick at 17th and Mission is a fantastic brunch. Another option is to start in Chinatown (just north of Union Squre) for dim sum.
  • From Castro take one of the N, J, etc. trains (every light rail train route in the city intersects at Church and Market) down to the Powell Street station. From the Mission you can take BART a couple of stops up to Powell Street.
  • Once at Powell Street hop on the Powell Street trolley. A quintessential SF experience.
  • Take the trolley up through the city where it will eventually stop at Lombard Street, which is known as the most crooked street in the world. Walk down the hill, take a few pictures and laugh at the tourists trying to drive down the damn thing.
  • Once at the bottom of the hill, turn left. You'll be walking towards the w
View WhyILikeGo.md

A slightly updated version of this doc is here on my website.

Why I Like Go

I visited with PagerDuty yesterday for a little Friday beer and pizza. While there I got started talking about Go. I was asked by Alex, their CEO, why I liked it. Several other people have asked me the same question recently, so I figured it was worth posting.

Goroutines

The first 1/2 of Go's concurrency story. Lightweight, concurrent function execution. You can spawn tons of these if needed and the Go runtime multiplexes them onto the configured number of CPUs/Threads as needed. They start with a super small stack that can grow (and shrink) via dynamic allocation (and freeing). They are as simple as go f(x), where f() is a function.

@matthewwithanm
matthewwithanm / models.py
Last active Dec 12, 2015
ImageSpec with Suffixed Filenames
View models.py
from django.db import models
from imagekit import ImageSpec
from imagekit.models import ImageSpecField
from imagekit.utils import get_field_info
from imagekit import register
import os
class TvSpec(ImageSpec):
suffix = '-tv'
@robgolding
robgolding / filtering.py
Created Nov 17, 2012
Django Class-Based View Mixins: Part 2
View filtering.py
class FilterMixin(object):
"""
View mixin which provides filtering for ListView.
"""
filter_url_kwarg = 'filter'
default_filter_param = None
def get_default_filter_param(self):
if self.default_filter_param is None:
raise ImproperlyConfigured(
@srid
srid / subcommand.go
Created Oct 24, 2012
golang simple subcommand parser
View subcommand.go
// A simple sub command parser based on the flag package
package subcommand
import (
"flag"
"fmt"
"os"
)
type subCommand interface {
@piscisaureus
piscisaureus / pr.md
Created Aug 13, 2012
Checkout github pull requests locally
View pr.md

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@robgolding
robgolding / login_required.py
Created Jul 11, 2012
Django Class-Based View Mixins: Part 1
View login_required.py
class LoginRequiredMixin(object):
"""
View mixin which requires that the user is authenticated.
"""
@method_decorator(login_required)
def dispatch(self, request, *args, **kwargs):
return super(LoginRequiredMixin, self).dispatch(
self, request, *args, **kwargs)
@nf
nf / hello-node.js
Created Jul 6, 2012
Hello world web server that scales across multiple processors
View hello-node.js
var cluster = require('cluster');
var http = require('http');
var numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {