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
"use strict"; | |
const qfApi = { | |
form: (src) => { | |
let form = new FormData() | |
for(let name in src) { | |
form.append(name, src[name]) | |
} | |
return form | |
}, |
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 path import path | |
import mimetypes | |
from flask import stream_with_context, Response | |
@app.route('/download/<id>') | |
def download(id): | |
# fp_as_string = my_source.get_a_file(id) | |
guessed, _ = mimetypes.guess_type(fp_as_string) | |
return Response(stream_with_context( | |
path(fp_as_string).chunks(2048, mode='rb')), mimetype=guessed) |
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
# My alternative to `.first_or_404()` that can also handle ValueError's (common use case for me). | |
# could of course be made to check for more common errors, but for now this has been what I need. | |
from flask import abort | |
def vcoerce(validate_p): | |
"Sanitises the result of a function from ValueError's and empty results" | |
try: | |
return validate_p() or abort(404) | |
except ValueError: |
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
-----BEGIN PGP MESSAGE----- | |
Version: GnuPG v1 | |
owFtkntQVFUcx3fBlkDXHqJkjxm4ksC0Mufec5+rpLQgRZlpmdqg6z2Pu1wXdmF3 | |
AVEpS0lzoNBAEypzakrF0FEcKrFBS8sUFQwc0nEUmSmXt1MpitpdxiZrOv+c8zvn | |
8/ue3/f8ToU13BRmfjknzTy2vTnRfPwKMr3yaJWwgkFeUszYVzA4R6eeQGjlUXMp | |
Y2fctBipfpqse2M9XkKTl/pj7zI2ppD6/LrXY1AgWUwGTIkthIeSNd3jor48nx7S | |
YnhNEHlN42TCKSoEUFJlVmA1IkAR8zxgASUiJpxsSGZ7/YF/3cqMaDp1YuwavGOE | |
T08THWkjfMHIAdGoIiOk8FSVAMCKLCAZCywBnCGrAhAC/dR319JSFXsRz/KhenOp | |
z51DnT6vd8Q0DughhOVZFnAyJ7JGRao/20gSiQwQUEVZ0LAmQaSJGsCYYABlSiEv |
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
# Re-try function with exponential back-off time | |
# `max`: Maximum amount of attempts | |
# `wait`: Wait time between attemps, in milliseconds | |
# `attempt`: Function to make one attempt, accepts arguments <nth try>, <callback upon success> | |
gently = @gently = (max, wait, attempt) -> | |
new Promise (fulfill, fail) -> | |
recur = (max, wait, attempt, n) -> | |
pending = setTimeout (-> | |
if n is max |
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
@closest = (x, y) -> | |
el = document.elementFromPoint x, y | |
unless el is null or el.nodeName is 'BODY' then el | |
else | |
slice = 2 * Math.PI / 8 | |
for radius in [5...200] by 8 | |
for step in [0...7] | |
angle = slice * step | |
[candX, candY] = [x + radius*Math.cos(angle), y + radius*Math.sin(angle)] | |
cand = document.elementFromPoint candX, candY |
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
#import <ifaddrs.h> | |
#import <arpa/inet.h> | |
/** | |
* Returns the IP adress of the device. | |
*/ | |
- (NSString*)ipaddr { | |
NSString *address = nil; | |
struct ifaddrs *interfaces = NULL; | |
struct ifaddrs *temp_addr = 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
_ = require 'underscore' | |
any = @any = (x) -> x | |
none = @none = (x) -> false | |
gt = @gt = (n) -> (x) -> x > n | |
eq = @eq = (p) -> (x) -> p == x | |
ne = @ne = (p) -> (x) -> x != p | |
match = @match = (P, L) -> | |
if P.length != L.length then false |
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
#include <stdarg.h> | |
#import <Foundation/Foundation.h> | |
@interface Cls : NSObject {} | |
-(int) takes_block: (int)limit withBlock:(int (^)(int first, ...))block; | |
@end | |
@implementation Cls | |
-(int) takes_block: (int)limit withBlock:(int (^)(int first, ...))block { |
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
#!/bin/bash | |
# Setup deployment target for Nginx + Python/uWSGI + Supervisor + Git | |
# From: https://gist.github.com/1210041 | |
function usage() { | |
cat << EOF | |
Usage: $0 PROJECT_NAME [DOMAIN] [OPTIONS] | |
Options: | |
-y No prompts, assume yes to all. |