Skip to content

Instantly share code, notes, and snippets.

def request_as_curl(request):
"""
construct a curl command from a (failed) request.
"""
url = request.url
headers = request.headers
data = request.body.decode("utf-8")
method = request.method
command = "curl -v -H {headers} {data} -X {method} {uri}"
@gfranxman
gfranxman / safepath.py
Last active February 18, 2022 23:28
Python safepath to replace os.path.join when you don't want the path components to tmp outside a root path preventing path traversal.
def safepath_join(head, *tail):
"""
combines path parts like os.path.join, but ensures the resultant directory
doesn't step outside of the path given as the root.
"""
root = os.path.abspath(head)
p = os.path.normpath(os.path.join(head, *tail))
if not p.startswith(root + os.path.sep):
raise ValueError(f"{p} steps outside {root}")
return p
@gfranxman
gfranxman / Makefile
Last active May 9, 2024 14:36
Makefile help target. Allows you to define groups of targets by starting a line with ## or expose a target with help test by including ## indented or after the target's dependencies.
.PHONY: help
# useage config
TARGETLEN:=$(shell echo 16)
# colors
BLUE:=$(shell echo "\033[0;36m")
GREEN:=$(shell echo "\033[0;32m")
YELLOW:=$(shell echo "\033[0;33m")
RED:=$(shell echo "\033[0;31m")
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gfranxman
gfranxman / simple_triangulation.cc
Created January 5, 2019 17:11 — forked from cashiwamochi/simple_triangulation.cc
This code is used for simple triangulation. It uses findEssentialMat, recoverPose, triangulatePoints in OpenCV. For viewer, PCL is used. You can watch 3D points and 2 camera poses. I checked alcatraz2.jpg and alcatraz1.jpg in pcv_data.zip (https://www.oreilly.co.jp/pub/9784873116075/). Perhaps there is something wrong ( actually it looks working…
#include <opencv2/opencv.hpp>
#include <pcl/common/common_headers.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <Eigen/Core>
#include <Eigen/LU>
#!/usr/bin/env python
"""
Bundle the site-packages of the current python environment into a zip file
If you have any wheels at `$(pwd)/wheels`, those will be used instead of
of the locally installed packages. For instance, if my pwd looked like
wheels/
|-- numpy-1.11.2-cp27-cp27mu-manylinux1_x86_64.whl

Keybase proof

I hereby claim:

  • I am gfranxman on github.
  • I am glenn_at_sfu (https://keybase.io/glenn_at_sfu) on keybase.
  • I have a public key whose fingerprint is 1402 5418 99F7 BAB7 CFDF A350 D69B 428B 0CC2 FCFA

To claim this, I am signing this object:

import requests
rip_url = 'https://www.guitartricks.com/blog/Goodbye-Glenn-Frey-a-Fallen-Eagle?utm_source=Guitar+Tricks+Newsletter&utm_campaign=bb3aded8a8-GT_NL_Prospects_1_29_2016&utm_medium=email&utm_term=0_832235591b-bb3aded8a8-95269893'
c = requests.get( rip_url ).content
c = c.replace('Frey', 'Franxman')
c = c.replace('Lewis', '')
c = c.replace('the Eagles', 'Scripps')
c = c.replace('trouble', 'python')
c = c.replace('music', 'APIs')
@gfranxman
gfranxman / debug.py
Last active August 29, 2015 14:25
django db log for prod
import logging
import django
from django.db import connection
if django.VERSION[1] > 7:
connection.force_debug_cursor=True
else:
connection.use_debug_cursor=True
l = logging.getLogger('django.db.backends')
@gfranxman
gfranxman / tzchoices.py
Created July 10, 2015 16:17
Django US TIMEZONE Choices.
import pytz
TIMEZONES = [ (t,t) for t in pytz.common_timezones if t.startswith("US/") ]
TIMEZONES.sort( key=lambda t: pytz.timezone(t[0])._utcoffset.seconds/3600, reverse=True )
>>> TIMEZONES
[('US/Eastern', 'US/Eastern'), ('US/Central', 'US/Central'), ('US/Mountain', 'US/Mountain'), ('US/Arizona', 'US/Arizona'), ('US/Pacific', 'US/Pacific'), ('US/Alaska', 'US/Alaska'), ('US/Hawaii', 'US/Hawaii')]
>>>