Skip to content

Instantly share code, notes, and snippets.

@sonkm3
sonkm3 / dpr_full.php
Created December 22, 2009 13:38
php DPZラジオ 長編をpodcastで聞く
<?php
/* DPZラジオ 長編をpodcastで聞く */
$dprfeed = file_get_contents( "http://podfeedsp.podcastjuice.jp/app/rss_convert.cgi?url=http%3A%2F%2Fdpz%2Ecocolog%2Dnifty%2Ecom%2Fdpr%2F" );
if($dprfeed){
$dprfeed = preg_replace('|<enclosure url="http://portal\.nifty\.com/[0-9]*/[0-9]*/[0-9]*/[a-z]/[0-9]*.mp3" length="[0-9]*" type="audio/mpeg" />|', "", $dprfeed);
$dprfeed = preg_replace('|<title>デイリーポータルZラジオ</title>|', "<title>デイリーポータルZラジオ(長編)</title>", $dprfeed);
print($dprfeed);
}else{
header('HTTP/1.0 500 Internal Server Error');
@sonkm3
sonkm3 / gist:1202394
Created September 8, 2011 01:38
python unicode and string
# -*- coding: utf-8 -*-
# 文字列型にマルチバイト文字を入れる(この場合はソースコードの文字コードのutf-8のはず)
string = 'あいう'
# 文字列をutf-8とみなしてユニコード文字列に変換する
unicode_string = string.decode('utf-8')
# 文字列をそのまま出力する
print string
@sonkm3
sonkm3 / gist:1202710
Created September 8, 2011 05:40
python classmethod/staticmethod
# -*- coding: utf-8 -*-
class Foo(object):
def method_1(self):
print self
@classmethod
def classmethod_1(cls):
print cls
@staticmethod
def staticmethod_1():
@sonkm3
sonkm3 / plurk.py
Created September 30, 2011 08:29
python plurk wrapper
# -*- coding: utf-8 -*-
from cgi import parse_qs
from urllib import urlencode
import oauth2
OAUTH_REQUEST_TOKEN_URL = 'http://www.plurk.com/OAuth/request_token'
OAUTH_ACCESS_TOKEN_URL = 'http://www.plurk.com/OAuth/access_token'
@sonkm3
sonkm3 / gist:1441546
Created December 7, 2011 05:11
apple script make Evernote note(put to "clip" notebook) of specified url.
display dialog "url" default answer ""
set clipurl to text returned of result
tell application "Evernote"
create note from url clipurl notebook "clip"
end tell
@sonkm3
sonkm3 / gist:1519116
Created December 25, 2011 11:32
python asyncoreでechoサーバーいろいろ見たけどよく分からない。
import asyncore
import socket
class EchoHandler(asyncore.dispatcher):
def __init__(self, sock):
asyncore.dispatcher.__init__(self, sock=sock)
self.send('welcome')
return
@sonkm3
sonkm3 / gist:1554556
Created January 3, 2012 11:27
python classmethod/staticmethod with inheritance
class Foo():
message = "I'm Foo class"
def method(self, foo):
self.foo = foo
print self.message
@classmethod
def class_method(cls, foo):
cls.foo = foo
@sonkm3
sonkm3 / follower2csv.py
Created January 5, 2012 09:52
python twitterのフォロワー一覧をcsvでみたかった
# -*- coding: utf-8 -*-
import sys, csv, StringIO
import tweepy
def get_followers(api, screen_name):
followers_count = api.get_user(screen_name = screen_name).followers_count
cursor = tweepy.Cursor(api.followers, screen_name = screen_name)
followers = cursor.items()
@sonkm3
sonkm3 / gist:1577137
Created January 8, 2012 03:58
python popenとかメモ
# 引数もリストで渡す
# 一行で
Popen(['ls','-l'],stdout=PIPE).stdout.read()
# 一行毎に
p = Popen(['ls','-l'],stdout=PIPE)
for line in p.stdout.read():
print line
# popen2は書いたまま
@sonkm3
sonkm3 / gist:1593511
Created January 11, 2012 07:15
python csvを文字列で取得したかった
# -*- coding: utf-8 -*-
import csv
import StringIO
s = StringIO.StringIO()
csv_writer = csv.writer(s)
list = [
{'name': 'item1', 'value': 'foo string'},
{'name': 'item2', 'value': 'bar "quoted" string'},