Skip to content

Instantly share code, notes, and snippets.

View andymccurdy's full-sized avatar

Andy McCurdy andymccurdy

  • San Francisco, CA
View GitHub Profile
"""
This is a simple benchmark that tests the performance of several
locking implementations. Each example implements a connection
pool that provides `get_connection()` to retrieve a connection
from the pool and `release()` to return a connection back to the
pool.
The `test()` function creates an instance of `pool_class` and
creates `num_threads` `threading.Thread` instances that simply call
`pool.get_connection()` and `pool.release()` repeatedly until
def purify(numbers):
return [i for i in numbers if i % 2 == 0]
# pub.py
import json
import redis
import time
r = redis.StrictRedis()
channels = range(1000)
messages_per_channel = 1000
import wtforms
class DummyPostData(dict):
def getlist(self, key):
v = self[key]
if not isinstance(v, (list, tuple)):
v = [v]
return v
[
{
"class": "tab_label",
"settings": ["highlight_modified_tabs"],
"parents": [{"class": "tab_control", "attributes": ["dirty"]}],
"fg": [120, 170, 250]
},
// QUICKPANEL SELECTED HIGHLIGHT
{
import os
import sublime_plugin
class NewFilePopupCommand(sublime_plugin.WindowCommand):
def run(self):
self.build_directory_tree()
self.window.show_quick_panel(self.labels, self.directory_selected)
def build_directory_tree(self):
class TemplateWidget(object):
"Uses a template to render the widget"
def __init__(self, template, get_value_callable=None):
self.template = template
self.get_value_callable = get_value_callable
def __call__(self, field, **kwargs):
kwargs.update({'field': field})
if self.get_value_callable:
kwargs['value'] = self.get_value_callable(field)
<?php
require_once('workflows.php');
$w = new Workflows();
function get_icon($weather) {
$icon = '';
switch($weather):
case 'Chance of Rain': $icon = 'icons/007.png'; break;
case 'Chance of Snow': $icon = 'icons/014.png'; break;
import time
from redis import ConnectionPool, Redis
class WaitingConnectionPool(ConnectionPool):
"Connection Pool that blocks if a connection is not available"
def make_connection(self):
while True:
if self._created_connections >= self.max_connections:
time.sleep(0.01)
self._created_connections += 1
Tech
Smartphones
Tablets
PCs
Accessories
iOS
Android
Windows
Windows Phone
Mac OS