Skip to content

Instantly share code, notes, and snippets.

View philfreo's full-sized avatar

Phil Freo philfreo

View GitHub Profile
@philfreo
philfreo / sha-padding.py
Created October 11, 2012 16:39
SHA1 Padding Attack
#!/usr/bin/env python
# http://www.vnsecurity.net/t/length-extension-attack/
# sha1 padding/length extension attack
# by rd@vnsecurity.net
#
import sys
import base64
from shaext import shaext
@philfreo
philfreo / 1_pdf.py
Last active January 30, 2024 16:20
Three ways to make a PDF from HTML in Python (preferred is weasyprint or phantomjs)
def render_pdf_weasyprint(html):
from weasyprint import HTML
pdf = HTML(string=html.encode('utf-8'))
return pdf.write_pdf()
def render_pdf_xhtml2pdf(html):
"""mimerender helper to render a PDF from HTML using xhtml2pdf.
Usage: http://philfreo.com/blog/render-a-pdf-from-html-using-xhtml2pdf-and-mimerender-in-flask/
"""
@philfreo
philfreo / gist:7257723
Created October 31, 2013 21:44
Facebook Perl source code from 2005. When browsing around thefacebook.com in 2005 the server spit out some server-side source code rather than running it. I believe this was for their old graph feature that let you visualize the graph between all your friends. The filename is `mygraph.svgz` and contains some gems such as a commented out "zuck" d…
#!/usr/bin/perl
use Mysql;
use strict;
use vars qw($school_name);
use vars qw($pass);
require "./cgi-lib.pl";
@philfreo
philfreo / gist:0a4d899de4257e08a000
Created August 22, 2014 21:38
4 different ways to save a Highcharts chart as a PNG (with and without a server)
// Method 1: simply use Highcharts built-in functionality (SVG -> Highcharts server -> PNG)
// Downside: won't work in webview native apps that don't handle the form response
highcharts.exportChart({
filename: filename
});
@philfreo
philfreo / html2pdf.py
Created June 21, 2013 22:50
A Flask view that returns HTML or generates a PDF
import mimerender
mimerender.register_mime('pdf', ('application/pdf',))
mimerender = mimerender.FlaskMimeRender(global_charset='UTF-8')
def render_pdf(html):
from xhtml2pdf import pisa
from cStringIO import StringIO
pdf = StringIO()
pisa.CreatePDF(StringIO(html.encode('utf-8')), pdf)
@philfreo
philfreo / Dockerfile
Last active September 16, 2022 19:34
test dockerfile syntax highlighting
FROM ubuntu:14.04.5
#Install newer version of Python 2.7
RUN DEBIAN_FRONTEND=noninteractive && apt-get update && apt-get install -y software-properties-common \
&& add-apt-repository -y ppa:fkrull/deadsnakes-python2.7 && apt-get update \
&& apt-get install -y python2.7=2.7.12-1~trusty1 && rm -rf /var/lib/apt/lists/*
@philfreo
philfreo / guide.md
Created August 4, 2015 23:35
Close.io API Getting Started Guide

Getting Started with the Close.io API

The Close.io API allows you to connect your app or service directly to your data in Close.io to search your existing leads, add new leads, and much more. In this guide, we're going to look at a couple of examples of how to accomplish some basic tasks using the API so that you can get started integrating Close.io into your current apps and workflows.

General API Information

Base URL

https://app.close.io/api/v1
@philfreo
philfreo / close-api.rb
Last active September 15, 2022 00:52
Close API Ruby RestClient Example
require 'rest_client'
require 'json'
API_KEY = 'your api key here'
api_base = 'https://' + API_KEY + ':@api.close.com/api/v1/'
# get info about yourself
RestClient.get api_base+'me/'
# post a lead
@philfreo
philfreo / png.js
Created May 30, 2017 23:21
PhantomJS program to generate a PNG based on stdin (e.g. SVG image)
// PhantomJS program to generate a PNG based on stdin (e.g. SVG image)
// Example: curl http://upload.wikimedia.org/wikipedia/commons/f/fd/Ghostscript_Tiger.svg | phantomjs png.js > test.png && open test.png
/*
From Flask/Python:
import os
from subprocess import Popen, PIPE, STDOUT
p = Popen(['phantomjs', '%s/png.js' % os.path.dirname(os.path.realpath(__file__))], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
out = p.communicate(input=svg.encode('utf-8'))[0]
strIO = StringIO.StringIO()
strIO.write(out)