Skip to content

Instantly share code, notes, and snippets.

@georgefs
georgefs / mongo.py
Last active December 19, 2015 17:48
mongodb /etc/init.d script
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2013 george
#
# Distributed under terms of the MIT license.
__all__ = []
import os
import sys
@georgefs
georgefs / myip.sh
Last active December 20, 2015 17:49
linux 查對外ip
function myip {
result=`wget -qO- http://myip.is/|grep "The IP used to connect to this webserver is "|sed 's/The IP used to connect to this webserver is//'`
echo $result
}
@georgefs
georgefs / gist:6361529
Last active December 21, 2015 20:29
django booleanfield issue

不知道有沒有人會直接用django form fields來做輸入驗證, 不過我是做了..

像是這樣

from django import forms
forms.DateTimeField().clean('2013-02-01')

datetime.datetime(2013, 2, 1, 0, 0)

可以直接幫你把字串解成時間..

@georgefs
georgefs / copy.vim
Created September 14, 2013 16:12
ubuntu vim copy
python import gtk
python import vim
vmap <silent> <C-C> y:let @0=substitute(@0,"\\","\\\\\\","gi")<CR>:let @0=substitute(@0,"\'","\\\\'","gi")<CR>:python gtk.clipboard_get().set_text('''<C-R>0''')<CR>:python gtk.clipboard_get().store()<CR>
@georgefs
georgefs / aesfield.py
Last active December 23, 2015 03:39
simple django 16 byte aes field
from django.db import models
from django.utils.encoding import smart_str
from Crypto.Cipher import AES
import base64
class AESField(models.TextField):
__metaclass__ = models.SubfieldBase
@georgefs
georgefs / copycat.mkd
Created September 22, 2013 10:48
description how to bindkey on your env

bash

~/.inputrc or /etc/.inputrc

"^V": "copycat "

zsh

@georgefs
georgefs / test.py
Last active December 24, 2015 13:59
simple test
try:
from cStringIO import StringIO
except:
from io import StringIO
from datetime import datetime
def test_join():
data = []
for i in range(1000000):
data.append(str(i))
一次決, 第二投標價得標, 最邪惡的地方在於..
你投標 只能決定你想要在得標的價格最高為多少..並不會直接影響得標金額
只要你覺得這次投標有這個價值.. 就可以直接投你的心裡底價, 不用再猶豫說這價錢會高別人太多..
利差就在於你的心裡底價 和 其他人的心理底價的差距
感覺這機制很棒, 因為每次得標都可以用合理的價錢來得標..不會因為自己對於這標過度高估, 有過度的損失..
teddy 說, 別人會把價錢拉上來..這觀點我覺得不對..每個人都會有最高價限制.
import dev_appserver
dev_appserver.fix_sys_path()
def get_auth():
import getpass
return raw_input('Username:'), getpass.getpass('Password:')
def connect(app_id):
from google.appengine.ext.remote_api import remote_api_stub
@georgefs
georgefs / sandbox.py
Last active December 27, 2015 07:19
simple wsgi sandbox
import urlparse
import sys
def app(env, start_response):
status = '200 OK'
start_response(status, [])
if env['REQUEST_METHOD'] != 'POST':
template = '''
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>