Skip to content

Instantly share code, notes, and snippets.

Commands

You can install Python-3.6 on debian 8 as follows:

wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
tar xvf Python-3.6.0.tgz
cd Python-3.6.0
./configure --enable-optimizations
make -j8
@alecordev
alecordev / gist:28bbca245865bb8aaf8b964ec72bcc72
Created March 19, 2017 15:13
Wordpress - Import uploaded files to media library
/*
* This function scans through all files in the wp-content/uploads
* folders and imports them into the media library. This should be
* included in your theme's functions.php file. Simply visit your
* website, including the URL param:
* http://www.example.org/?import_non_existing_media_library_entries=1
*
* Plan on it timing out a few times. Just keep refreshing. It won't
* duplicate files being imported.
*/
@alecordev
alecordev / gist:6daf2e12d51476c5baa850db322869a4
Created March 19, 2017 17:48
Some Django customizations
Fixing Settings
We’re on a mission to fix your bad settings files here. We show this layout to new clients and I’m constantly surprised how few people know this is even possible to do. I blame the fact that while everyone knows that settings are just Python code, they don’t think about them as Python code.
So let’s fix up our settings. For our foo project we’re going to have 4 environments: dev, stage, jenkins, and production. So let’s give each it’s own file. The process to do this is:
In foo/foo/ make a settings directory and create an empty __init__.py file inside it.
Move foo/foo/settings.py into foo/foo/settings/base.py
Create the individual dev.py, stage.py, jenkins.py, and prod.py files in foo/foo/settings/. Each of these 4 environment specific files should simply contain the following:
from base import *
- http://www.devdungeon.com/content/working-binary-data-python
- https://docs.python.org/2/library/shutil.html#shutil.make_archive
@alecordev
alecordev / .py
Last active July 24, 2018 16:27
Python decorate instance method example - Timed decorator
import types
class Timed(object):
def __init__(self, f):
self.func = f
def __call__(self, *args, **kwargs):
start = dt.datetime.now()
ret = self.func(*args, **kwargs)
time = dt.datetime.now() - start
@alecordev
alecordev / .py
Last active July 24, 2018 16:29
Python SimpleNamespace
class SimpleNamespace:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def __repr__(self):
keys = sorted(self.__dict__)
items = ('{}={!r}'.format(k, self.__dict__[k]) for k in keys)
return '{}({})'.format(type(self).__name__, ', '.join(items))
@alecordev
alecordev / gist:d950dd08587fff5e19fa2874293758d0
Created April 6, 2017 09:50
Console redirect stdout stdin stderr
dir > a.txt 2>&1
from IPython.display import SVG, display
@alecordev
alecordev / .py
Last active July 26, 2017 14:18
Python path
os.chdir(path)
os.path.dirname(os.path.abspath(__file__))
os.path.dirname(os.path.realpath(__file__))
os.path.abspath(os.path.dirname(sys.argv[0]))
# Long
import os
print('Path at terminal when executing this file')
print(os.getcwd() + '\n')
http://airbnb.io/superset/index.html