Skip to content

Instantly share code, notes, and snippets.

View k4zy's full-sized avatar

Kazuki Yoshida k4zy

  • Cookpad.Inc
  • Yebisu/Tokyo
View GitHub Profile
import math
import string
class BinPacking:
def minBins(self, tuple_items):
items = list(tuple_items)
bin_count = 0
while 100 in items and 200 in items:
items.remove(100)
#include <stdio.h>
// 1.一番ベーシックな構造体の定義の文法
struct sample1{
float f;
};
int main()
{
struct sample1 a;
{
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"font_face": "Migu 1M",
"font_size": 13,
"highlight_modified_tabs": true,
"ignored_packages":
[
"Emmet",
"CoffeeCompile"
],
@k4zy
k4zy / gist:5270944
Last active December 15, 2015 13:59
android base adapter templete
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
public class MainViewListAdapter extends BaseAdapter{
List<MainViewListEntry> entries;
@k4zy
k4zy / gist:5127651
Created March 10, 2013 08:33
近江鉄道のスクレイピング スクリプトでけた~ サンプルurl: http://kazy.oops.jp/debug/oumi.php?id=167_7_1 http://www.busqr.com/jikoku/01/stop/iku/xxx.html <= xxxの所をidで渡す感じです
<?php
$id = $_GET['id']; //GETパラメーターを取得
function is_on_service_time($line){
return preg_match("/<FONT\scolor=\"\#0000cc\">\d{2}:<\/FONT>\s<A\shref=\"bin\/\d{5}\.html\">\d{2}<\/A>/xsiu",$line,$item);
}
$result_array = array();
$url = "http://www.busqr.com/jikoku/01/stop/iku/".$id.".html";
@k4zy
k4zy / gist:5124237
Created March 9, 2013 13:56
navitimeから時刻表を抽出するスクレイピング スクリプトです. サンプルurl : http://kazy.oops.jp/doshisha/navitime.php?direction=up&station=doshishamae (jsonを返します) 今は同志社近辺に対応する形になってますが一般化はできます かなり辛い感じなコードがたっぷりなので書き直します すいません
<?php
$direction = $_GET['direction'];
$station = $_GET['station'];
$direction_num = $direction == 'up' ? 0 : 1;
$station_id = array('shintanabe'=>'00004328','kyotanabe'=>'00001755','imadegawa'=>'00002735','demachiyanagi'=>'00003573','doshishamae'=>'00006957','kodo'=>'00001781');
$station_code = array('shintanabe'=>'近鉄京都線','kyotanabe'=>'片町線','imadegawa'=>'京都市営烏丸線','demachiyanagi'=>'京阪本線',);
$url = "http://www.navitime.co.jp/diagram/".$station_id[$station];
header('Content-Type:text/html; charset=UTF-8');
$context = stream_context_create(array(
'http' => array(
@k4zy
k4zy / gist:4516007
Last active December 11, 2015 00:19
芳賀先生のネット講義のサイトからのストリーミングurl(非公開も含む) を取得する phpスクリプト
<?php
$html = file_get_contents('http://ishss10.doshisha.ac.jp/~hhaga/Teaching/dsa-2012/');
$html = mb_convert_encoding($html, 'utf8', 'sjis-win');
preg_match("/<table\swidth=\"60%\"\sborder=\"1\">(.*?)<\/table>/xsiu",$html,$table);
preg_match_all("/<TD.*?>(第.{1,2}回)<\/TD>.*?(http:\/\/dsmsf.doshisha\.ac\.jp\/Gateway\/contentPlayAction\.do\?contentId=\d{12})/xsiu",$table[1],$tr_list);
$hash = array();
foreach($tr_list[2] as $key => $value)
$hash[$tr_list[1][$key]]=$value;
print_r($hash);
?>