Skip to content

Instantly share code, notes, and snippets.

public function setPhoto()
{
$options = array(
'file_src' => '',
'is_image' => true,
'with_delete' => false,
'template' => get_partial('default/formEditImage', array('image' => $this->getObject())),
);
$this->setWidget('photo', new sfWidgetFormInputFileEditable($options, array('size' => 40)));
$this->setValidator('photo', new opValidatorImageFile(array('required' => false)));
# -*- coding: utf-8 -*-
class Hoge(object):
def foo(self, num):
"""
0~num-1までの数字をリスト形式で作成する
>>> a = Hoge()
>>> a.foo(5)
[0, 1, 2, 3, 4]
"""
return [e for e in range(num)]
@mogi
mogi / myprofiler.py
Created August 19, 2012 14:55 — forked from methane/myprofiler.py
Casual MySQL profiler using "SHOW FULL PROCESSLIST"
#!/usr/bin/env python
# coding: utf-8
"""myprofiler - Casual MySQL Profiler
https://github.com/methane/myprofiler
"""
import os
import sys
@mogi
mogi / trello survey
Created September 27, 2012 04:03
analysis trello's json file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import simplejson
from collections import defaultdict
FILE_PATH = u'/Users/mogihiroki/Downloads/limited-quest.json'
f=open(FILE_PATH)
data=simplejson.load(f)
f.close()
@mogi
mogi / stats_by_url.py
Created October 4, 2012 09:42
stats url
#!/usr/bin/python
# coding: UTF-8
"""
urlからテキストを抽出して解析
"""
import re
import urllib2
import time
from collections import defaultdict
@mogi
mogi / url_crawler.py
Created October 12, 2012 09:25
url_crawler
#!/usr/bin/python
# coding: UTF-8
"""
何かしらの2chURL一覧からスレのIDを取ってファイルに保存
"""
import re
import urllib2
import copy
def get_html(url):
@mogi
mogi / markdown.md
Created November 22, 2012 09:58 — forked from azu/markdown.md
markdownで書かれたmarkdownチートシート

Code - コードの挿入

puts 'The best way to log and share programmers knowledge.'

puts 'The best way to log and share programmers knowledge.'

また、コードをインライン表示することも可能です。

@mogi
mogi / README
Created November 29, 2012 11:53
forked: Tree in the breeze
fork したものを写経してみた。
割とtypoしててびびった。
@mogi
mogi / gist:4286962
Last active October 14, 2015 01:28
lifegame
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
"""
class BaseRule(object):
def __init__(self, cell):
self.cell = cell
def valid():
raise NotImplementedError
@mogi
mogi / gist:4510622
Last active December 10, 2015 23:38
trim duplicate object
def trim_duplicate_by_objects_list(objects_list, obj_attr_name):
trimd = {}
for o in objects_list:
key = getattr(o, obj_attr_name)
if not key:
continue
trimd[key] = o
return trimd.values()