Skip to content

Instantly share code, notes, and snippets.

View joar's full-sized avatar
:bowtie:
Not wearing a bowtie

Joar Wandborg joar

:bowtie:
Not wearing a bowtie
View GitHub Profile
@joar
joar / player.py
Last active December 13, 2015 18:18
Autoplay videos from a folder
import os, subprocess, sys
while True:
try:
[subprocess.call(['mplayer', '-fs', os.path.join(os.path.abspath(sys.argv[1]), i)]) for i in os.listdir(sys.argv[1])]
except Exception as exc:
print('Fail: ' + str(exc))
@joar
joar / plugins.rst
Last active December 14, 2015 02:58
@joar
joar / cloudfiles-co.py
Last active December 14, 2015 02:59
Copy files from BasicFileStorage to CloudFilesStorage in GNU MediaGoblin
import logging
logging.getLogger().setLevel(logging.DEBUG)
logging.basicConfig()
from mediagoblin import mg_globals
from mediagoblin.gmg_commands import util as commands_util
from mediagoblin.storage.cloudfiles import CloudFilesStorage
@joar
joar / pytests-out.txt
Created February 23, 2013 19:25
CPython time + timedelta (#17267)
== CPython 3.4.0a0 (default, Feb 24 2013, 18:38:43) [GCC 4.7.2]
== Linux-3.5.0-23-generic-x86_64-with-debian-wheezy-sid little-endian
== /home/joar/git/cpython/build/test_python_30879
Testing with flags: sys.flags(debug=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, verbose=0, bytes_warning=0, quiet=0, hash_randomization=1)
[1/2] test_datetime
test_astimezone (test.datetimetester.TestSubclassDateTime_Pure) ... ok
test_backdoor_resistance (test.datetimetester.TestSubclassDateTime_Pure) ... ok
test_bad_constructor_arguments (test.datetimetester.TestSubclassDateTime_Pure) ... ok
test_basic_attributes (test.datetimetester.TestSubclassDateTime_Pure) ... ok
test_basic_attributes_nonzero (test.datetimetester.TestSubclassDateTime_Pure) ... ok
@joar
joar / werkzeug-debug.diff
Created March 1, 2013 20:51
Use werzeug.debug.DebuggedApplication with GNU MediaGoblin
diff --git a/mediagoblin/app.py b/mediagoblin/app.py
index 607d599..4c48ba8 100644
--- a/mediagoblin/app.py
+++ b/mediagoblin/app.py
@@ -47,6 +47,7 @@ class MediaGoblinApp(object):
... this is the heart of the program!
"""
+
def __init__(self, config_path, setup_celery=True):
@joar
joar / mgunicorn.py
Last active June 18, 2018 02:22
Run GNU MediaGoblin via gunicorn
import logging.config
from mediagoblin.app import MediaGoblinApp
from beaker.middleware import SessionMiddleware
logging.config.fileConfig('paste_local.ini')
app = MediaGoblinApp('mediagoblin_local.ini')
app = SessionMiddleware(app, {
import socket, sys, json, requests
r = requests.post(
'https://api.github.com/authorizations',
headers={'Content-Type': 'application/json'},
data=json.dumps({'scopes': ['repo'], 'note': socket.gethostname()}),
auth=(sys.argv[1], sys.argv[2]))
assert r.status_code == 201
@joar
joar / gotcha.rst
Created April 5, 2013 21:42
Python pytest virtualenv gotcha

I encountered this issue:

(mediagoblin)➜  ~VIRTUAL_ENV git:(master) ✗ ./runtests.sh                                                                         belz
Using ./bin/py.test
+ CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_tests
+ exec ./bin/py.test ./mediagoblin/tests --boxed
/home/joar/git/mediagoblin/local/lib/python2.7/site-packages/pytest-2.3.4-py2.7.egg/_pytest/assertion/oldinterpret.py:3: DeprecationWarning: The compiler package is deprecated and removed in Python 3.x.
  from compiler import parse, ast, pycodegen

Don't break our necks over SQLite's inability to ALTER things. SQLite has almost no support for table or column alteration, and this is likely intentional. Alembic's design is kept simple by not contorting it's core API around these limitations, understanding that SQLite is simply not intended to support schema changes. While Alembic's architecture can support SQLite's workarounds, and we will support these features provided someone takes the initiative to implement and test, until the SQLite developers decide to provide a fully working version of ALTER, it's still vastly preferable to use Alembic, or any migrations tool, with databases that are designed to work under the assumption of in-place schema migrations taking place.

https://pypi.python.org/pypi/alembic/0.4.0

@joar
joar / features.xml
Created April 11, 2013 12:02
Android Resources - Nested arrays
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="text_allshare">
<item name="primary">Allshare Play &amp; Cast - smidig delning</item>
<item name="secondary">Anslut smidigt till andra mobila enheter, datorer eller TV-apparater för dela med dig av din multimedia oavsett var du befinner dig.</item>
</string-array>
<string-array name="text_foo">
<item name="primary">Shape Match</item>
<item name="secondary">Visualisera dina idéer bättre genom att förvandla ojämna streck till prydliga geometriska former. Shape Match korrigerar automatiskt linjer och former.</item>
</string-array>