Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
"""
Used to fetch cover art. Based heavily on obeythepenguin's
`Cover Fetcher' (http://coverfetcher.sourceforge.net/)
obeythepenguin AT users.sourceforge.net, but attempting to
provide a CLI interface.
"""
import argparse
@felipeochoa
felipeochoa / xltoken.py
Last active August 29, 2015 14:23
A regular expression to tokenize excel formulae
import re
TOKEN_RE = re.compile(r"""
(?P<scientific>[1-9](?:\.[0-9]+)?[Ee][+-]?[1-9][0-9]*)|
(?P<string>"(?:[^"]*"")*[^"]*"(?!"))|
(?P<link>'(?:[^']*'')*[^']*'(?!'))|
(?P<sq_bracket>\[[^]]*\])|
(?P<error>\#NULL!|\#DIV/0!|\#VALUE!|\#REF!|\#NAME?|\#NUM!|\#N/A)|
(?P<wspace>\ +)|
(?P<operator>[-+*/^&=%]|>=|<=|<>|>(?!=)|<(?![=>]))|
@felipeochoa
felipeochoa / Postgres migration.md
Last active May 25, 2020 16:45
Migrating from sqlite to postgres

Postgres migration

I had to migrate what had started as a toy website and has now become a real website from running on sqlite to postgres today. I use a push-to-deploy setup, so the process was a bit tricky. I only needed like 10 minutes of downtime to do it, but had to make sure I had all the steps in order. For future record:

  1. Update requirements.txt to include psycopg2 and push the latest version of production branch so that any migrations get applied on the sqlite DB and psycopg2 is installed in the virtual env.
// ==UserScript==
// @name Check Netflix availability from you IMDB watchlist
// @namespace https://github.com/felipeochoa
// @description Filter your IMDB watchlist based on Netflix availability
// @author https://github.com/felipeochoa
// @include http://www.imdb.com/user/*/watchlist
// @include http://www.imdb.com/user/*/watchlist?*
// @include https://www.imdb.com/user/*/watchlist
// @include https://www.imdb.com/user/*/watchlist?*
// @version 1.0
(defun fov-list-packages-and-versions ()
"Returns a list of all installed packages and their versions"
(mapcar
(lambda (pkg)
`(,pkg ,(package-desc-version
(cadr (assq pkg package-alist)))))
package-activated-list))
;; Unfortunately the following function does not work
;; if the specific versions you need aren't the latest
/* When using a PureComponent, changes to the store will still trigger re-renders of the children
*
* Tested with https://jsfiddle.net/poqf128w/4/
*
* https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js
* https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js
* https://cdnjs.cloudflare.com/ajax/libs/redux/3.6.0/redux.js
* https://cdnjs.cloudflare.com/ajax/libs/react-redux/4.4.5/react-redux.js
*/
const names = [
@felipeochoa
felipeochoa / react-context-as-dynamic-scope.jsx
Created November 13, 2016 09:15
Testing the overriding of parent context in children
/**
* Children can override parent's context, which means context is a form of dynamic scoping.
* Tested at: https://jsfiddle.net/79e293az/
* https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js
* https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js
*/
class Parent extends React.PureComponent {
getChildContext() {

Keybase proof

I hereby claim:

  • I am felipeochoa on github.
  • I am fovc (https://keybase.io/fovc) on keybase.
  • I have a public key whose fingerprint is 6AEE AC8F 9B16 8B71 430C 16A6 EA6F 759A D809 0E61

To claim this, I am signing this object:

@felipeochoa
felipeochoa / DOCX spec.md
Created March 8, 2017 19:37
Quick overview of how the DOCX format works

How the DOCX spec works

The standard can be downloaded from the ISO website at [this direct link][iso direct link]

DOCX documents are a zipped folder containing several interacting components in a word doc. The main ones are:

  • word/document.xml: The main document content
  • word/styles.xml: Name style information (e.g. "Header 1"), similar to CSS
@felipeochoa
felipeochoa / mu4e-thread-folding.el
Created March 16, 2017 18:05
Thread folding in mu4e
;; Refactored from https://github.com/djcb/mu/pull/783
(defun mu4e~headers-msg-unread-p (msg)
"Check if MSG is unread."
(let ((flags (mu4e-message-field msg :flags)))
(and (member 'unread flags) (not (member 'trashed flags)))))
(defvar mu4e-headers-folding-slug-function
(lambda (headers) (format " (%d)" (length headers)))