Skip to content

Instantly share code, notes, and snippets.

View nashibao's full-sized avatar

Naoki Shibayama nashibao

View GitHub Profile
@nashibao
nashibao / cache.py
Created April 9, 2012 04:33
django cache key
def _generate_cache_key(request, headerlist, key_prefix):
"""Returns a cache key from the headers given in the header list."""
ctx = md5_constructor()
for header in headerlist:
value = request.META.get(header, None)
if value is not None:
ctx.update(value)
path = md5_constructor(iri_to_uri(request.path))
cache_key = 'views.decorators.cache.cache_page.%s.%s.%s' % (
key_prefix, path.hexdigest(), ctx.hexdigest())
@nashibao
nashibao / leaderboard.coffee
Created April 16, 2012 09:05
Meteor Sample(Leaderboard) in CoffeeScript
Players = new Meteor.Collection("players")
if Meteor.is_client
Template.leaderboard.players = () ->
return Players.find {}, {sort: {score: -1, name: 1}}
Template.leaderboard.selected_name = () ->
player = Players.findOne(Session.get("selected_player"));
return player and player.name
@nashibao
nashibao / session.py
Created May 2, 2012 10:10
modify django-redis-session
def create(self):
while True:
self._session_key = self._get_new_session_key()
try:
self.save(must_create=True)
except CreateError:
continue
self.modified = True
return
@nashibao
nashibao / firebase_chat.html
Created May 3, 2012 14:06
firebase sample
<html>
<head>
<title>guest&#39;s Firebase Project</title>
<script type='text/javascript' src='http://static.firebase.com/demo/firebase.js'></script>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
<link rel='stylesheet' type='text/css' href='http://www.firebase.com/css/example.css'>
</head>
<body>
<div id='messagesDiv'></div>
<input type='text' id='nameInput' placeholder='Name'>
// Node.h
class Node {
String name; //id
Node** children;
Node* parent;
int numOfChildren;
String* nameList;
int layernum;
@nashibao
nashibao / gist:3039677
Created July 3, 2012 13:23
example answer..
codes = {}
def convert(tag):
return codes.setdefault(tag, 1 << codes.length)
def desc(node):
for child in node.childs:
child_code = convert(child.tag)
child.code = child_code | node.code
@nashibao
nashibao / sync_tactics.md
Created October 24, 2012 07:23
sync tactics

settings

server side settings

  • updated_at : update time
  • pk (guid) : identifier which is unique belong all devices.
  • is_active (is_deleted)
  • is_conflicted(transient, default=false)

client side settings

  • updated_at: the same as server side
@nashibao
nashibao / gist:6059118
Last active December 20, 2015 02:49
How is a 'this' argument changed in javascript ? ref: [じゃあ this の抜き打ちテストやるぞー](http://qiita.com/KDKTN/items/0b468a07410d757ac609)
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
'use strict';
var a, b, c, e, f, fnc;
a = function(){
@nashibao
nashibao / virtual_knockout.jade
Last active January 31, 2016 11:07
jade mixins for knockout.js virtual element. https://github.com/visionmedia/jade/pull/958
mixin with(val)
<!-- ko with: !{val} -->
block
<!-- /ko -->
mixin if(val)
<!-- ko if: !{val} -->
block
<!-- /ko -->