Skip to content

Instantly share code, notes, and snippets.

View boris317's full-sized avatar

Shawn Adams boris317

View GitHub Profile
@boris317
boris317 / flask_tar.py
Created September 10, 2012 20:57
Stream a tar file with flask.
import os
from cStringIO import StringIO
import tarfile
from flask import Flask, Response
app = Flask(__name__)
def get_string_io_len(s):
@boris317
boris317 / flask_shell.py
Created September 25, 2012 17:00
IPython interactive shell + Flask App
from exampleapp import app
import IPython
app.testing = True
test_client = app.test_client()
welcome_message = """Welcome to your Flask CLI environment.
The following variables are available to use:
app -> Your Flask app instance.
export function renderComponent(component, query, variables) {
let {loading, error, data} = useQuery(query, {variables});
if (loading) {
return null;
}
if (error) {
console.log(error);
}
class AirBookingService {
private final Database db;
private final BookingService bookings;
private static final Map<String, User> userCache = new HashMap<>();
public AirBookingService() {
db = new Database();
bookings = BookingServiceFactory.getService();
}
@boris317
boris317 / foo.js
Created September 12, 2018 13:48
POST with ajax
$("#newDeviceForm").submit(function(e) {
// Don't let the browser submit automatically
e.preventDefault();
$.ajax({
type: "POST",
url: "http://rad8prod-env.paxsdtgzng.us-east-1.elasticbeanstalk.com/devices",
headers: {
Authorization: "dev_env_pw"
},
data: this.serialize(),
@boris317
boris317 / statsd-tcpdump.sh
Last active November 14, 2017 16:43
Verify data is being fed to collectd and statsd
# statsd
sudo tcpdump -i eth0 -p -n -s 1500 -A udp port 8125
# statsd flushing to graphite
sudo tcpdump 'port 2005 or 2009' -s0 -A
# collectd
sudo tcpdump -i eth0 -p -n -s 1500 -A udp port 25827
let plugins = getPlugins()
.flatMap(p => p)
// Group plugins by consumer_id or app_id
.reduce((obj, p) => {
let id = p.consumer_id || p.api_id;
if (id in obj) {
obj[id].push(p);
} else {
obj[id] = [p];
}
Shawn's Intellij Shortcuts
Symbols:
⌥ Option
⌘ Command
⇧ Shift
⌃ Control
← Left arrow
→ Right Arrow
↑ Up Arrow
@boris317
boris317 / test.js
Created July 29, 2016 01:32
RXJS Chaining HTTP Calls
var http = require('http');
var RX = require('rx');
var request = require('request');
function get(url) {
return RX.Observable.create(function(observer) {
request(url, function(err, response, body) {
if (err) {
observer.onError(err);
return;
#!/usr/bin/env python
import sys
print "\\n".join([l.strip() for l in sys.stdin.readlines()])