Skip to content

Instantly share code, notes, and snippets.

func (c *Client) Get(key string) (*CacheItem, error) {
var item *CacheItem
err := c.connection.Call("RPC.Get", key, &item)
return item, err
}
func (c *Client) Put(item *CacheItem) (bool, error) {
var added bool
err := c.connection.Call("RPC.Put", item, &added)
return added, err
var (
c *Client
err error
dsn = "localhost:9876"
cacheItem = &CacheItem{Key: "some key", Value: "some value"}
)
func init() {
c, err = NewClient(dsn, time.Millisecond*500)
func TestColdGet(t *testing.T) {
item, _ := c.Get(cacheItem.Key)
if item != nil {
t.Errorf("Cache key should not exist: %s\n", cacheItem.Key)
}
}
func TestPut(t *testing.T) {
_, err := c.Put(cacheItem)
if err != nil {
PASS
ok _/Users/ka/rpc_tutorial 0.038s
@anandkunal
anandkunal / gist:324963
Created March 8, 2010 07:24
ColdFusion Tagging Library
<cfset tags_list = " CaMELCaSE comma, 'singlequoted' <b>bold</b> ""doublequoted"" double double this should be over the limit now " />
<cfset amount = 10 />
<cfset length = 20 />
<pre><cfset tags_list = trim(tags_list) />
<cfset tags_list = lcase(tags_list) />
<cfset tags_struct = structnew() />
@anandkunal
anandkunal / gmail_pagination_hack.js
Created March 8, 2010 07:03
Gmail Pagination Hack
// 1: older page for all mail
49: function() {
currentPage = GrabCurrentAllMailPage();
if (currentPage >= 2) {
window.location.hash = "#all/p" + (currentPage-1);
}
},
// 2: newer page for all mail
50: function() {
@anandkunal
anandkunal / list_predicates.py
Created March 8, 2010 07:07
Python List Predicates
from types import FunctionType
from UserList import UserList
class PredicateList(UserList):
def Exists(self, predicate):
"""Returns true if the predicate is satisfied by at least one list member."""
if type(predicate) is FunctionType:
for item in self.data:
if predicate(item):
return True
@anandkunal
anandkunal / duplicate_image.py
Created March 8, 2010 07:38
I whipped up this quick recipe using the Python Imaging Library. It's nothing fancy, but it gets the job done. Hacking this script to scoop/compare images in a directory is rather trivial.
import Image
def is_the_same(base, test_image):
for i in range(len(base)):
if (base[i] - test_image[i]) != 0:
return False
return True
base = Image.open('base.png').getdata()
bad = Image.open('bad.png').getdata()
total_pages = 68;
full_document_path = "~/Project/Assets/catalog.pdf";
full_output_path = "~/Project/Assets/jpg/";
function open_document(page) {
FileReference = new File(full_document_path);
PDFOpenOptions = new PDFOpenOptions();
PDFOpenOptions.page = page;
PDFOpenOptions.resolution = 72;
app.open(FileReference, PDFOpenOptions);
import sets
import string
whitespace = sets.ImmutableSet(string.whitespace)
def qs(test_string, abbreviation, offset=None):
offset = offset or 0
if len(abbreviation) == 0: return 0.9
if len(abbreviation) > len(test_string): return 0.0