Skip to content

Instantly share code, notes, and snippets.

View cloudysunny14's full-sized avatar

Kiyonari Harigae cloudysunny14

View GitHub Profile
# Copyright (C) 2014 Kiyonari Harigae <lakshmi at cloudysunny14 org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@cloudysunny14
cloudysunny14 / ndb_pagination.py
Last active December 9, 2015 22:09
Flask pagination with using GAE's NDB. a great source for ideas and inspiration by http://flask.pocoo.org/snippets/44/ and https://gist.github.com/4406666 by Tom Willis. grateful feelings :)
def cursor_from_offset(q, offset, per_page, cursor=None):
"""
the maximum cursor position you can get in one shot is
1250 (page_size=250, offset=1000), so to get a cursor
beyond that requires a bit of work.
will return None if not results and more
"""
MAX_OFFSET = 1000
if offset <= MAX_OFFSET:
@cloudysunny14
cloudysunny14 / random_selection.py
Created November 16, 2012 10:40
Random selection of elements in a list, with no repeats
import random
def select(data):
while data:
if data != []:
index = random.randint(0, len(data) - 1)
elem = data[index]
data[index] = data[-1]
del data[-1]
yield elem
@cloudysunny14
cloudysunny14 / CompatibleUtil.m
Created November 15, 2012 11:00
Compatible with forward frameworks apis.
/* Copyright (c) 2012 cloudysunny14
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@cloudysunny14
cloudysunny14 / gist:3549915
Created August 31, 2012 07:37
inputreader for GoogleAppEngine Mapreduce. [input_readers.py]
#!/usr/bin/env python
#
# Copyright 2012 cloudysunny14
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#