Skip to content

Instantly share code, notes, and snippets.

View paxan's full-sized avatar

Pavel Repin paxan

  • aws.amazon.com
  • Seattle, WA
View GitHub Profile
@paxan
paxan / demo
Last active August 29, 2015 14:19
try-let
```
> (try-let [x (/ 5 1) y (/ 5 2)] [x y])
[5 5/2]
> (try-let [x (/ 5 1) y (/ 5 0)] [x y])
#<ArithmeticException java.lang.ArithmeticException: Divide by zero>
```
@paxan
paxan / librato.go
Created December 5, 2014 23:55
HACK: Librato measurement sender
package main
import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"log"
"net/http"
"regexp"
@paxan
paxan / with-open-seq.clj
Last active August 29, 2015 13:56
with-open-seq
(require '[clojure.core.async :refer [chan close! go >! <!!]])
(defmacro with-open-seq
"Like with-open, but only closes resources when
the sequence generated by the body is exhausted."
[bindings & body]
`(let [c# (chan)]
(go
(try
(with-open ~bindings
@paxan
paxan / fibosayer.py
Last active December 26, 2015 17:49
Says numbers of Fibonacci sequence starting from the 50th one and goes on forever.
#!/usr/bin/env python
from __future__ import print_function
import random
import time
from subprocess import check_call
from shlex import split
voices = tuple('Agnes Kathy Princess Vicki Victoria Bruce Fred Junior Ralph'.split()) + \
@paxan
paxan / Node Under Pressure.md
Last active December 21, 2015 12:09
Putting a simple one-dyno Node.js app under pressure on Heroku

What the app does

It receives certain JSON events as HTTP POSTs, parses them, and writes received JSON with along with some extra metadata to stdout using console.log(). POST-ed data does not usually exceed ~800 bytes per request.

It runs with node 0.10.15 engine on Heroku with just one web dyno. Also it uses Express 3.3.4 web service library.

Under pressure

I've subjected the app to some traffic by means of blitz.io:

@paxan
paxan / RedirectSpy.java
Last active December 17, 2015 09:38
A demo of shortened URL expansion using Apache HttpComponents (http://hc.apache.org/)
import com.google.common.base.Joiner;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.ProtocolException;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.DefaultRedirectStrategy;
import org.apache.http.protocol.HttpContext;
@paxan
paxan / gist:4982896
Last active December 13, 2015 22:09
This snippet of fenced Clojure code breaks Jekyll. Related GH issue: https://github.com/mojombo/jekyll/issues/814
---
layout: post
title: Boom!
category: posts
---
# Repro
Here's a code example:
@paxan
paxan / README.md
Last active December 11, 2015 23:28
A script that launches OS X FileMerge to inspect Git diffs

Intro

Sometimes you may want a better way to inspect/review Git diffs than what GitX and other tools provide (which is basically a glorified pretty printed linear view of diff hunks).

If you're on a Mac, try ["gdiff" shell script.][1] It's a wrapper that launches OS X FileMerge application to inspect diffs.

Installation

Just place gdiff somewhere in your PATH, chmod +x it too.

Usage

You should invoke gdiff just like git diff from inside a repo directory.

@paxan
paxan / .screenrc
Created January 29, 2013 18:46
.screenrc by @offby1
# -*-conf-space-*-
# This screenrc file was obtained as-is from Pavel's friend
# Eric Hanchrow (https://github.com/offby1). It just works!
# Typical screen installations use Control-A to access screen
# functions, but this one uses Control-Z. As far as I know,
# it's the same as a typical screen setup in every other way.
# This seems to interfere least with Emacs
escape ^Zz
@paxan
paxan / mylogger.py
Created December 25, 2012 23:31
Try "gunicorn --logger-class mylogger.MyLogger mylogger:app" for both cases: Exhibit A and Exhibit B. Also observe that when you do "python mylogger.py" you will get "AttributeError: 'module' object has no attribute 'glogging'" in the case of Exhibit A.
if True:
import gunicorn # Exhibit A
else:
import gunicorn.glogging # Exhibit B
class MyLogger(gunicorn.glogging.Logger):
pass
def app(environ, start_response):
data = "Hello, World!\n"