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
# coding:utf-8 | |
# Snapperクラス | |
class Snapper(object): | |
def __init__(self): | |
self.state = 'OFF' | |
self.hasPower = False # 電源が供給されているか | |
self.isWorking = False # Snapperが稼働しているか | |
self.previous = None # 前に接続しているSnapper | |
self.follow = None # 次に接続しているSnapper |
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
def session_required(session_name, redirect_url=None): | |
""" | |
関数にセッションチェックを行う機能を追加する | |
デコレータ関数 | |
""" | |
def outer_wrapper(func): | |
def session_checker(*args, **kargs): | |
if session.get(session_name) is not None: | |
return func(*args, **kargs) | |
else: |
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
<?php | |
/** | |
* read a cookie | |
* | |
* @access private | |
* @return void | |
*/ | |
protected function _get_cookie() | |
{ |
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
def dump_queryset(qs, format='yaml', indent=2, filename=None): | |
""" QuerySet をカレントディレクトリにyamlで出力するCLI Utility """ | |
if not isinstance(qs, QuerySet): | |
raise ValueError(u'QuerySet以外はシリアライズできません') | |
data = serializers.serialize(format, qs, indent=indent) | |
if not filename: | |
model_name = qs[0].__class__.__name__ | |
now_str = datetime.now().strftime('%Y_%M_%d__%H_%M_%S') |
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
# -*- coding:utf-8 -*- | |
def divide(num, by): | |
""" num を バランスよく by分割する関数 | |
e,g:num=13, by=2 => [7, 6] | |
num=30, by=4 => [8, 8, 7, 7] | |
""" | |
quotient, rest = divmod(num, by) | |
ans = [quotient for i in range(by)] |
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
class test(object): | |
"""A property whose value is computed only once. """ | |
def __init__(self, function): | |
self._function = function | |
def __get__(self, obj, _=None): | |
if obj is None: | |
return self | |
value = self._function(obj) |
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
def call_classmethod(*args): | |
""" | |
モジュール内のクラスのクラスメソッドを実行しやすくするためのヘルパ関数 | |
args にはメソッドを実行したいclassを指定 | |
""" | |
current_module = sys.modules[__name__] | |
factories = {} | |
results = {} |
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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 http://lua-users.org/wiki/TableSerialization | |
function print_r (t, name, indent) | |
local tableList = {} | |
function table_r (t, name, indent, full) | |
local serial=string.len(full) == 0 and name | |
or type(name)~="number" and '["'..tostring(name)..'"]' or '['..name..']' | |
io.write(indent,serial,' = ') | |
if type(t) == "table" then | |
if tableList[t] ~= nil then io.write('{}; -- ',tableList[t],' (self reference)\n') |
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
package main | |
import ( | |
"crypto/tls" | |
"fmt" | |
"net/mail" | |
"net/smtp" | |
"github.com/scorredoira/email" | |
) |
OlderNewer