Skip to content

Instantly share code, notes, and snippets.

View craiga's full-sized avatar
🤓

Craig Anderson craiga

🤓
View GitHub Profile
@craiga
craiga / .pylintrc
Last active February 21, 2018 16:01
Pylint configuration for new Django projects
[MASTER]
load-plugins = pylint.extensions.mccabe, pylint_django
ignore-patterns = manage.py, \d{4}.*.py
good-names = application, urlpatterns
[REPORTS]
output-format = colorized
[TYPECHECK]
generated-members = url, py*
@craiga
craiga / dosomething.py
Last active June 26, 2020 13:28
Django Command Boilerplate
"""Command to do something."""
import logging
from django.core.management.base import BaseCommand
logger = logging.getLogger(__name__)
class Command(BaseCommand):
@craiga
craiga / main.py
Last active January 31, 2017 11:02
Do Python modules load once and only once?
def main():
print("Importing tell the time module")
import tell_the_time
print("Importing tell the time module again")
import tell_the_time as tell_the_time_again
if __name__ == '__main__':
main()
/**
* Get memory usage information.
*
* Requires {@link https://gist.github.com/3759346 strtobytes}.
*
* @author Craig Anderson <craiga@craiga.id.au>
* @link https://gist.github.com/craiga/9e35e52168aefe58b9eb
*/
function get_mem_info()
{
@craiga
craiga / randomstring.php
Last active August 29, 2015 14:01
Generate a random string.
<?php
/**
* Generate a random string.
*
* Based on {@link https://gist.github.com/craiga/4075392 a JavaScript function}.
*
* @param $alphabet (optional) The alphabet used to generate a random string.
* @param $minLength (optional) The minimum length of the string. 10 by default.
* @param $maxLength (optional) The maximum length of the string. 20 by default.
@craiga
craiga / cookieencode.php
Last active August 29, 2015 14:00
Encode a string so it can be safely used with setrawcookie.
<?php
/**
* Encode a string so it can be safely used with {@link http://php.net/setrawcookie setrawcookie}.
*
* @author Craig Anderson <craiga@craiga.id.au>
* @link https://gist.github.com/craiga/11390574
*/
function cookieencode($s) {
$result = $s;
@craiga
craiga / Timable.php
Last active January 3, 2016 04:29
Functions for timing.
<?php
/**
* Functions for timing. Requires {@link https://gist.github.com/craiga/1849563 Logging} and {@link https://gist.github.com/craiga/3186287 formatTime}.
*
* @author Craig Anderson <craiga@craiga.id.au>
* @link https://gist.github.com/craiga/8409711
*/
trait Timable {
@craiga
craiga / Locking.php
Last active December 25, 2015 11:48
Locking functions
<?php
require_once(realpath(dirname(__FILE__ )) . "/../logging-trait/Logging.php");
/**
* Functions for locking.
*
* _lock, _unlock and _isLockedByOther for file-based, non-blocking locking.
*
* @author Craig Anderson <craiga@craiga.id.au>
@craiga
craiga / unique_rand.php
Last active December 20, 2015 06:29
Get a unique random integer.
<?php
/**
* Get a unique random integer.
*
* @author Craig Anderson <craiga@craiga.id.au>
* @link https://gist.github.com/craiga/6085988
*/
function unique_rand($min = 0, $max = null) {
static $prev = array();
<?php
/**
* Flatten an array, preserving keys.
*
* @author Craig Anderson <craiga@craiga.id.au>
* @link https://gist.github.com/craiga/5855194
*/
function flattenArray($in) {
$out = array();