This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PASS | |
ok _/Users/ka/rpc_tutorial 0.038s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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() /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |