Skip to content

Instantly share code, notes, and snippets.

@rectalogic
rectalogic / LumaWipe.glsl
Created June 17, 2014 02:11 — forked from glslioadmin/TEMPLATE.glsl
GLSL.io Transition (v1)
#ifdef GL_ES
precision highp float;
#endif
uniform sampler2D from, to;
uniform float progress;
uniform vec2 resolution;
uniform sampler2D lumaTex;
uniform bool invertLuma;
uniform float softness;
import httplib
import filedata
def post_multipart(host, selector, files):
"""
Post files to an http host as multipart/form-data.
files is a sequence of (name, filename, value) elements for data to be uploaded as files
Return the server's response page.
"""
@rectalogic
rectalogic / KeyValueObserver.swift
Last active January 19, 2018 10:25
Key Value Observing (KVO) in Swift using closures
import Foundation
typealias KVObserver = (source: NSObject, keyPath: String, change: [NSObject : AnyObject]) -> Void
class KVOContext {
private let source: NSObject
private let keyPath: String
private let observer: KVObserver
func __conversion() -> UnsafeMutablePointer<KVOContext> {
{
"Type" : "Notification",
"MessageId" : "d9217124-7fde-5ce1-9382-3d9cd955c2f8",
"TopicArn" : "arn:aws:sns:us-west-2:262456549263:NotificationDeliveryFailure-play",
"Subject" : "DeliveryFailure event for app com.cureatr.messenger.play (MPNS)",
"Message" : "{\"DeliveryAttempts\":1,\"EndpointArn\":\"arn:aws:sns:us-west-2:262456549263:endpoint/MPNS/com.cureatr.messenger.play/23d917f8-25ba-36ff-bf08-b5da28402d83\",\"EventType\":\"DeliveryFailure\",\"FailureMessage\":\"mpns behaved in an unexpected way\",\"FailureType\":\"DeliveryFailedPerm\",\"MessageId\":\"258d8a40-1e8c-553b-b3d5-c6f8b807e695\",\"Resource\":\"arn:aws:sns:us-west-2:262456549263:app/MPNS/com.cureatr.messenger.play\",\"Service\":\"SNS\",\"Time\":\"2014-10-15T16:43:55.894Z\"}",
"Timestamp" : "2014-10-15T16:43:55.945Z",
"SignatureVersion" : "1",
"Signature" : "a5jaug9K3/H6DTps492z9SUXHPKMtm1oGI43aKBoykI2ikR8y7SZXPAfcsqWROAnWz3EJxRlXUklLXWBx2AFMH8Twiroi8thjrXhB2HQpAaMC7Z/zkg8yYcFrHS79UcIVhjIOAptIgC6Pdpele+Y/moiU8vETI2TKtsRfYgrvyCnQ89fW
>>> class F(object):
... __class__ = list
...
>>> f = F()
>>> f.__class__
<type 'list'>
>>> isinstance(f, F)
True
>>> isinstance(f, list)
True
@rectalogic
rectalogic / results
Last active August 29, 2015 14:10
limit sort
[aw@jello tmp] $ python sort-slice.py
45920256
[aw@jello tmp] $ python sort-heapq.py
5808128
struct tm time;
strptime("1934-11-02T10:45:11", "%FT%T%z", &time);
long ts = timegm(&time);
NSDate *d = [NSDate dateWithTimeIntervalSince1970:ts];
NSLog(@"%@", d);
from abc import ABCMeta
class ListLike:
__metaclass__ = ABCMeta
ListLike.register(list)
ListLike.register(tuple)
ListLike.register(_FieldSequence)
>>> isinstance([], ListLike)
class Enum(object):
def __init__(self, **kwargs):
self._values = set()
for k, v in kwargs.items():
setattr(self, k, v)
self._values.add(v)
def validate(self, values):
return set(values).issubset(self._values)
@rectalogic
rectalogic / scale.py
Last active September 15, 2015 15:09
bounds_w = 100
bounds_h = 100
im_w, im_h = im.size
scales = (bounds_w / im_w, bounds_h / im_h)
if scale_type == "meet":
scale = min(scales)
elif scale_type == "fill":
scale = max(scales)