Skip to content

Instantly share code, notes, and snippets.

View docker-fns.sh
#!/usr/bin/env bash
hash docker &>/dev/null;
if [ $? -eq 0 ]; then
alias d="docker"
function docker-rm-untagged-imgs() {
[[ $1 == "force" ]] && OPTS="--force" || OPTS="";
docker images | grep "^<none>" | awk '{print "docker rmi '$OPTS' "$3}' | sh
}
View unittest-queue.py
import unittest
from unittest.mock import patch, call
class MyQueue(object):
def send(self, message):
pass
View decorator-example.py
from functools import wraps
def my_decorator(f):
@wraps(f)
def wrapper(*args, **kwds):
print('Calling decorated function')
return f(*args, **kwds)
return wrapper
View og-worker.py
import queue
from threading import Thread
class Worker(Thread):
def __init__(self, q, other_arg, *args, **kwargs):
self.q = q
self.other_arg = other_arg
super().__init__(*args, **kwargs)
View threaded-decorator.py
import time
from queue import Queue
from threading import Thread
def threaded(f, daemon=False):
def wrapped_f(q, *args, **kwargs):
"""this function calls the decorated function and puts the
result in a queue"""
@meganlkm
meganlkm / thread-queue-1.py
Created May 19, 2020
Thread/Queue Example
View thread-queue-1.py
import random
import time
from queue import Queue
from threading import Thread
WORKERS = 2
class Worker(Thread):
@meganlkm
meganlkm / laravel_shared_hosting_project.sh
Last active May 19, 2019
setup a laravel 4.2 project to deploy to a shared hosting provider
View laravel_shared_hosting_project.sh
#!/bin/bash
myproject='myproject'
mywwwdir='public_html'
# initialize project
composer create-project laravel/laravel $myproject 4.2.*
cd $myproject
perl -pi -e "s|/public|/../${mywwwdir}|" bootstrap/paths.php
@meganlkm
meganlkm / laravel5_shared_hosting_project.sh
Last active Jan 3, 2019
setup a laravel5 project to deploy to a shared hosting provider
View laravel5_shared_hosting_project.sh
#!/bin/bash
myproject='myproject'
mywww='public_html'
# initialize project
composer create-project laravel/laravel $myproject --prefer-dist
cd $myproject
# fix paths to public
View get-dist-and-version.sh
#!/usr/local/bin/bash
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release
OS=$NAME
VER=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
# linuxbase.org
OS=$(lsb_release -si)
@meganlkm
meganlkm / app.py
Created May 22, 2018
download a rendered template as a StringIO object in a Flask app
View app.py
from StringIO import StringIO
from flask import Flask, render_template, send_file
app = Flask(__name__)
@app.route('/bootstrap')
def bootstrap():
str_io = StringIO()
You can’t perform that action at this time.