Skip to content

Instantly share code, notes, and snippets.

View mgp's full-sized avatar
🤗

Michael Parker mgp

🤗
View GitHub Profile
@mgp
mgp / redis_memory_benchmark_v1.py
Created April 6, 2011 04:27
Quantifies the memory optimizations of Redis 2.2, and memory costs of zsets versus sets.
"""
Copyright Michael Parker 2011.
Program to quantify the memory usage of:
a. The compact hash and set implementations in Redis 2.2 described at
http://redis.io/topics/memory-optimization and
http://redis.io/presentation/Pnoordhuis_whats_new_in_2_2.pdf versus their
counterparts that do not contain integers. For the comparisons to be
meaningful, be sure to have hash-max-zipmap-entries and
set-max-intset-entries present in your redis.conf file.
@mgp
mgp / gist:2356195
Created April 11, 2012 01:35
Django test suite problem

Hi all,

I'm having trouble creating a test suite in Django 1.3.

Say I have an installed app in a directory called app_name. One of the files in that directory is foo.py which defines a class named Foo. I want to test that, so I also have a file that directory called foo_test.py which defines a class named FooTest. That file looks like:

import unittest
import foo

class FooTest(unittest.TestCase):

@mgp
mgp / gist:5298276
Created April 3, 2013 03:41
Custom activity to choose a contact with a phone number. But normally you just want new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI).
package com.example;
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.content.ContentUris;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
<!DOCTYPE html>
<html>
<head>
<style>
body > div {
border: 2px solid green;
padding: 50px;
margin: 10px
}
@mgp
mgp / sharebot.coffee
Created October 31, 2014 00:58
Share Bot
# Description:
# Forwards messages to ShareBears
request = require('request')
module.exports = (robot) ->
robot.respond /.*/i, (msg) ->
sender = msg.envelope.user.mention_name
body = msg.match[0].substring(10)
formData = { user_id: sender, text: body }
@mgp
mgp / p4merge4git.md
Last active June 15, 2021 19:11 — forked from tony4d/p4merge4git.md
Edit to handle spaces in filenames
/**
A UIAlertView that owns its delegate so that the client that displays the UIAlertView
does not need to own it.
This is useful when the client that displays the UIAlertView is not the UIAlertDelegate
implementation. It is free to initialize an object to serve as the delegate that exists
only for the lifetime of the UIAlertView, thereby fostering decomposition.
*/
class OwnedDelegateAlertView: UIAlertView {
private let ownedDelegate: AnyObject?
/**
UIAlertViewDelegate used when the user can only go back, and so the associated handler
has no parameters.
*/
private class BackOnlyErrorDelegate: NSObject, UIAlertViewDelegate {
private let handler: () -> Void
private init(handler: () -> Void) {
self.handler = handler
}
@mgp
mgp / gist:6ca63f80283d1090a243
Created February 26, 2015 22:43
OwnedDelegateAlertView
//
// ViewController.swift
// deinit-failure
//
// Created by Mike Parker on 2/26/15.
// Copyright (c) 2015 Mike Parker. All rights reserved.
//
import UIKit
package org.khanacademy.core.topictree.models;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import org.khanacademy.core.topictree.identifiers.ContentItemIdentifiable;
import org.khanacademy.core.topictree.identifiers.ContentItemIdentifier;
import org.khanacademy.core.topictree.identifiers.ContentItemKind;
/**