Skip to content

Instantly share code, notes, and snippets.

View dmitric's full-sized avatar

Dmitri Cherniak dmitric

View GitHub Profile
import { svgPathProperties } from "svg-path-properties"
calculateConnectionsBetweenPaths (d, lastd, segments) {
// Take in two "d" attribute string and break then down into N segements
// and return a list of those points
const connections = []
// Given a path's value of d, get the total length of the path
const pp = new svgPathProperties(d)

Keybase proof

I hereby claim:

  • I am dmitric on github.
  • I am dmitric (https://keybase.io/dmitric) on keybase.
  • I have a public key ASA_hdjGryyH4aXeTpn4vr5AHZFlqhgPvOrbjh0ftsrUago

To claim this, I am signing this object:

@dmitric
dmitric / README.md
Last active August 29, 2015 14:06
A nice way to generate external apis

I hate using third party language libraries because they are often just a crappier more OOP'd version of a nice rest api. Here's a sample framework for automatically generating call chains that map to the RESTful url.

Just define the verbs and nouns you want to use in the resources set. And when the API changes or adds new endpoint, just toss em in there too!

POST /buttons maps to api.buttons.post

or

@dmitric
dmitric / amazon_signing.py
Last active December 24, 2015 13:38
Signing AWS requests
def _sign_params(self, params, host, uri="/", action="GET"):
buffer = "%s\n" % action
buffer += "%s\n" % host
buffer += "%s\n" % uri
buffer += '&'.join("%s=%s" % (self._quote(i[0]), self._quote(i[1])) for i in sorted(params.items()))
signature = base64.b64encode(
hmac.new(self.secret_access_key, buffer, hashlib.sha256).digest()
)
return signature
@dmitric
dmitric / video_links.py
Created August 19, 2013 09:21
Misaka based HtmlRenderer that lets you embed youtube and vimeo videos
@dmitric
dmitric / mdx_video.py
Created August 19, 2013 07:40
A dead simple python markdown extension to embed youtube or vimeo videos in markdown. Using oembed is a terrible idea if you have lots of links on a page, and the other implementations I saw were sloppy. You can still use regular links to vimeo and youtube too.
# -*- coding: utf-8 -*-
from markdown import Extension
from markdown.util import etree
from markdown.inlinepatterns import Pattern
SOURCES = {
"youtube": {
"re": r'youtube\.com/watch\?\S*v=(?P<youtube>[A-Za-z0-9_&=-]+)',
"embed": "//www.youtube.com/embed/%s"
},
@dmitric
dmitric / fun_orm.py
Last active June 21, 2018 11:16
A simple read-only ORM like functionality using python's __getattr__. Example uses tornado's torndb Connection and query
class Backend(object):
"""Allows access to backend and removes logic from handlers"""
def __init__(self):
"""Inititalize with the variables you need"""
self.__users_data = None
self.db = Connection(
options.db_host,
options.db,
user=options.db_user,
@dmitric
dmitric / auth.py
Created January 17, 2013 04:54
Old examples of auth in tornado
class FacebookGraphLoginHandler(BaseHandler, tornado.auth.FacebookGraphMixin):
@tornado.web.asynchronous
def get(self):
my_url = (self.request.protocol + "://" + self.request.host +"/login/facebook?next="+tornado.escape.url_escape(self.get_argument("next", "/")))
if self.get_argument("code", False):
self.get_authenticated_user(redirect_uri=my_url,client_id=self.settings["facebook_api_key"],client_secret=self.settings["facebook_secret"],code=self.get_argument("code"),callback=self._on_auth,extra_fields=['email'])
return
self.authorize_redirect(redirect_uri=my_url,client_id=self.settings["facebook_api_key"],extra_params={"scope": "read_stream,email,offline_access"})
def _on_auth(self, user):
@dmitric
dmitric / lol.m
Created October 10, 2012 05:32
How to make regular expressions in objC
static inline NSRegularExpression * TagRegularExpression() {
static NSRegularExpression *_tagRegularExpression = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_tagRegularExpression = [[NSRegularExpression alloc] initWithPattern:@"\\#[\\w]+"
options:NSRegularExpressionCaseInsensitive
error:nil];
});
@dmitric
dmitric / p.py
Created October 3, 2012 16:56
Template
Traceback (most recent call last):
File "/Users/DLC/.virtualenvs/b/lib/python2.7/site-packages/tornado/web.py", line 1021, in _stack_context_handle_exception
raise_exc_info((type, value, traceback))
File "/Users/DLC/.virtualenvs/b/lib/python2.7/site-packages/tornado/stack_context.py", line 258, in _nested
yield vars
File "/Users/DLC/.virtualenvs/b/lib/python2.7/site-packages/tornado/stack_context.py", line 228, in wrapped
callback(*args, **kwargs)
File "/Users/DLC/.virtualenvs/b/lib/python2.7/site-packages/tornado/gen.py", line 382, in inner
self.set_result(key, result)
File "/Users/DLC/.virtualenvs/b/lib/python2.7/site-packages/tornado/gen.py", line 315, in set_result