Skip to content

Instantly share code, notes, and snippets.

shevron /
Last active Nov 20, 2020
Generate an arbitrary CSV file of about given size in Python
"""Use to generate a large CSV file for testing purposes. Will write CSV data to STDOUT
Usage: python 512000000 # Make a ~512mb CSV file
import csv
import sys
from itertools import count
def make_csv_row(counter, row_width, zero_fill=8):
shevron /
Created Oct 6, 2020
Demo of using Azure Blob Storage API for simple multipart upload flow
"""Test Azure Multipart Uploads
import base64
import logging
import os
from itertools import count
from typing import BinaryIO, Generator, Tuple
import click
from azure.core.exceptions import ResourceNotFoundError
shevron / docker-compose-dev.yaml
Created Apr 9, 2019
Docker compose file defining external CKAN dependencies
View docker-compose-dev.yaml
# Docker compose for external services, assuming main ckan services are run
# outside of Docker
version: "3"
shevron /
Created Oct 23, 2016
Shoppimon API Examples (bash / curl / jq)
# The following example requires `jq` to parse JSON
BEARER_TOKEN=$(curl -s -X POST \
-H "Content-Type: application/json" \
-d '{"grant_type":"client_credentials","client_id":"'$CLIENT_ID'","client_secret":"'$CLIENT_SECRET'"}' |\
jq -rM '.access_token')
echo "Bearer token: $BEARER_TOKEN"
shevron /
Last active Apr 3, 2019
Examples: MySQL named locks and Python context managers
"""same logic as in above, but using a locking context manager
from app_services import db_session
from locking_context import named_lock
def single_running_func():
"""this code should never execute in parallel
with named_lock(db_session, 'my_lock', 5):
# Do some stuff that should not run in parallel
shevron / test.php
Last active Aug 29, 2015 — forked from anonymous/test.php
A better way to write to /dev/null
View test.php
// Get 10mb of data from /dev/zero
$infp = fopen('/dev/zero', 'r');
$data = fread($infp, 1024 * 1024 * 10);
echo "Peak memory usage: ", number_format(memory_get_peak_usage()), " bytes\n";
shevron / LICENSE
Last active Apr 28, 2020
Send EC2 instance memory usage stats to CloudWatch using boto and IAM Roles
Copyright (c) 2015, Shahar Evron
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
shevron / builtin-ws-wrapper.php
Created Aug 18, 2012
A wrapper script for serving ZF apps with PHP's built in Web server
View builtin-ws-wrapper.php
* PHP Built-in Web Server wrapper for ZF apps
$reqUri = $_SERVER['REQUEST_URI'];
if (strpos($reqUri, '?') !== false) {
$reqUri = substr($reqUri, 0, strpos($reqUri, '?'));
shevron / fix-cs-multiuse.php
Created Aug 12, 2012
Convert single, comma separated mutli-namspace use statements into multiple use calls with single namespace references
View fix-cs-multiuse.php
* Convert single use calls with comma separated list of namespaces into
* multiple, stand-alone use calls
* Usage: php cs-fix-use.php <file>
* Will overwrite <file> with new version. If <file> is omitted, stdin / stdout
* will be used.
shevron / Uri.php
Created Jun 18, 2012
Zend Framework 2.0 Uri validator
View Uri.php
namespace Zend\Validator;
class Uri extends AbstractValidator
const INVALID = 'uriInvalid';
protected $_messageTemplates = array(
self::INVALID => "Provided input is not a valid URL"