Skip to content

Instantly share code, notes, and snippets.

View hiphamster's full-sized avatar

Alex Yelluas hiphamster

View GitHub Profile
@hiphamster
hiphamster / flask_binary.py
Created August 30, 2019 05:41 — forked from Miserlou/flask_binary.py
Flask serving binary data example
import io
from flask import Flask, send_file
app = Flask(__name__)
@app.route('/logo.jpg')
def logo():
"""Serves the logo image."""
with open("logo.jpg", 'rb') as bites:
@hiphamster
hiphamster / gist:c352c9b264ecc920f0592aec5d412269
Created August 7, 2019 00:04 — forked from hest/gist:8798884
Fast SQLAlchemy counting (avoid query.count() subquery)
def get_count(q):
count_q = q.statement.with_only_columns([func.count()]).order_by(None)
count = q.session.execute(count_q).scalar()
return count
q = session.query(TestModel).filter(...).order_by(...)
# Slow: SELECT COUNT(*) FROM (SELECT ... FROM TestModel WHERE ...) ...
print q.count()
@hiphamster
hiphamster / gist:c848783f4392a4799675ebd0d00a962d
Created August 6, 2019 00:08
Installing mysqlclient with pip
Installing mysqlclient with pip needs to know about openssl
/opt/local is where macports are installed
LDFLAGS="-L/opt/local/lib" CPPFLAGS="-I/opt/local/include/openssl" pip install mysqlclient
@hiphamster
hiphamster / update-alternatives_port-select.md
Last active June 19, 2019 20:42
Setup vi / vim alternatives on mac and linux

Linux

Debian-based systems i.e. Ubuntu have update-alternatives, a system that maintains symbolic links to default commands

From the man page:

EXAMPLES
       There are several packages which provide a text editor compatible with vi, for example nvi and vim. 
 Which one is used is controlled by the link group vi, which includes links for the program itself 

Typing vagrant from the command line will display a list of all available commands.

Be sure that you are in the same directory as the Vagrantfile when running these commands!

Creating a VM

  • vagrant init -- Initialize Vagrant with a Vagrantfile and ./.vagrant directory, using no specified base image. Before you can do vagrant up, you'll need to specify a base image in the Vagrantfile.
  • vagrant init <boxpath> -- Initialize Vagrant with a specific box. To find a box, go to the public Vagrant box catalog. When you find one you like, just replace it's name with boxpath. For example, vagrant init ubuntu/trusty64.

Starting a VM

  • vagrant up -- starts vagrant environment (also provisions only on the FIRST vagrant up)
@hiphamster
hiphamster / tidy.conf
Created November 7, 2018 05:42 — forked from paultreny/tidy.conf
The config file I use for tidy-html5. $ tidy -config <path/to/tidy.conf> input.html > output.html
// paulcode.com
// tidy-html5 config file (mine's named "tidy.conf")
// tidy documentation is here: http://tidy.sourceforge.net/#docs
// tidy-html5 documentation here: http://w3c.github.io/tidy-html5/quickref.html#drop-empty-elements
join-classes: no
logical-emphasis: no
drop-empty-elements: no
anchor-as-name: no
doctype: auto
@hiphamster
hiphamster / gist:be10896f1d693b7e5cfd94f864d85ef8
Created August 31, 2018 06:55 — forked from emptyhammond/gist:1603144
Make a PUT request with jQuery.ajax()
$.ajax({
type: 'POST', // Use POST with X-HTTP-Method-Override or a straight PUT if appropriate.
dataType: 'json', // Set datatype - affects Accept header
url: "http://example.com/people/1", // A valid URL
headers: {"X-HTTP-Method-Override": "PUT"}, // X-HTTP-Method-Override set to PUT.
data: '{"name": "Dave"}' // Some data e.g. Valid JSON as a string
});
/* Some clients do not support PUT or it’s difficult to send in a PUT request. For these cases, you could POST the request with a request header of X-HTTP-Method-Override set to PUT. What this tells the server is that the intended request is a PUT. Obviously this relies on the API you are accessing making use of the X-HTTP-Method-Override Header.*/
@hiphamster
hiphamster / browser_history.md
Created August 30, 2018 21:30 — forked from dropmeaword/browser_history.md
Playing around with Chrome's history

Browser histories

Unless you are using Safari on OSX, most browsers will have some kind of free plugin that you can use to export the browser's history. So that's probably the easiest way. The harder way, which seems to be what Safari wants is a bit more hacky but it will also work for other browsers. Turns out that most of them, including Safari, have their history saved in some kind of sqlite database file somewhere in your home directory.

The OSX Finder cheats a little bit and doesn't show us all the files that actually exist on our drive. It tries to protect us from ourselves by hiding some system and application-specific files. You can work around this by either using the terminal (my preferred method) or by using the Cmd+Shft+G in Finder.

Finder

Once you locate the file containing the browser's history, copy it to make a backup just in case we screw up.

@hiphamster
hiphamster / find_anagrams.cl
Created March 1, 2018 23:03
sample clojure code
(ns anagram
(:gen-class))
(defn anagrams-for
"select anagrams from the list of words"
([] "nothing")
([word words]
(let [ word-chars (frequencies (for [c (clojure.string/lower-case word)] c))
@hiphamster
hiphamster / pytest.md
Created March 1, 2018 09:00 — forked from kwmiebach/pytest.md
pytest cheat sheet

Usage

(Remember to create a symlink pytest for py.test)

pytest [options] [file_or_dir] [file_or_dir] ...

Help: