Skip to content

Instantly share code, notes, and snippets.

View PyYoshi's full-sized avatar
🌍
Working from The World

MISAWA Yoshihiro PyYoshi

🌍
Working from The World
View GitHub Profile
@PyYoshi
PyYoshi / get_google_cookie.py
Created November 28, 2011 08:05
Google Client Loginからcookieの取得
@PyYoshi
PyYoshi / strip_tag.py
Created December 8, 2011 08:52
htmlデータからタグを除去する
from lxml.html import fromstring
def strip_tags(html):
"""
htmlデータからタグ除去したテキストデータを抽出する
※scriptタグとstyleタグを無視
Args:
html: str, パースしたいhtmlデータ
Returns:
text: str, タグ除去されたテキストデータ
@PyYoshi
PyYoshi / async_dis.py
Created December 20, 2011 07:04
asyncoreのテスト クライアントとサーバで1+1の処理を通信します。 async_dis.py→cli.pyの順に起動すること。
# -*- coding:utf-8 -*-
import asyncore
import socket
import os
import sys
addresses = [
('localhost',252525), # dispatcher
]
@PyYoshi
PyYoshi / scrape_startups_japan.py
Created January 9, 2012 08:15
startups-japan.comから企業リンクのみ抽出
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from lxml.html import fromstring
import urllib
result_links = []
urls = [
'http://www.startups-japan.com/clients/index/page:1/',
@PyYoshi
PyYoshi / wiki_complink.py
Created January 9, 2012 10:32
Wikipediaにある企業一覧から企業リンクを抽出するコード
@PyYoshi
PyYoshi / grant_naruto.js
Created February 19, 2012 09:12
ircBot-console用、自動なると付加スクリプト
/*
#-------------------------------------------------------------------------------
# Name: grant naruto
# Purpose: ircBot-console用、自動なると付加スクリプト
# Version: 0.1
#
# History:
# 0.1 初リリース
#
# Author: PyYoshi
@PyYoshi
PyYoshi / handle_googlecookie.py
Created June 4, 2012 09:56
cookiejarをファイルに保存するのではなく文字列として使えるようにするアレ。 google cookie専用
# coding:utf-8
# google用cookie
# License: MIT
import cookielib
import simplejson
def cookiejar_to_jsonstring(cookiejar):
cookies = cookiejar._cookies['.google.com']['/']
cookies_list = []
@PyYoshi
PyYoshi / padding.py
Created June 4, 2012 10:28
指定block sizeまでパッディングするlambda関数。 lambdaってちょー便利!
# coding:utf8
#!/usr/bin/env python
mes = "python prpr"
block_size = 32
padding = 'x'
pad = lambda s: s + (block_size - len(s) % block_size) * padding
print pad(mes)
@PyYoshi
PyYoshi / find_free_port.py
Created June 5, 2012 15:22
空きポートを見つける関数 #qiitaのテスト ref: http://qiita.com/items/238a431ff40c22db3d7c
# coding:utf8
import socket
def find_free_port():
""" 空きポートを見つける関数 """
serversock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
serversock.bind(('127.0.0.1',0))
address, port = serversock.getsockname()
serversock.close()
@PyYoshi
PyYoshi / xor.py
Created June 9, 2012 10:18
Pythonで文字列をXORする関数 ref: http://qiita.com/items/dc60edfed7afc1d302e7
# coding:utf-8
import base64
from itertools import cycle,izip
def xor_enc_base64(ss, key):
key = cycle(key)
return base64.b64encode(''.join(chr(ord(x) ^ ord(y)) for (x,y) in izip(ss, key)))
def xor_dec_base64(ss, key):
key = cycle(key)