Skip to content

Instantly share code, notes, and snippets.

View sykwer's full-sized avatar

Takahiro Ishikawa sykwer

View GitHub Profile
@sykwer
sykwer / fotmat_str.es6.jsx
Created March 8, 2017 13:38
Reactjs + lodashでの実装で、改行コードを含むテキストをフォーマットする。先頭末尾の改行はtrimして3つ以上続く改行は2つに縮める。
const str = "some awesome sentence";
const formatted_str = _.map(
_.replace(str, /(\r\n){3,}|\r{3,}|\n{3,}/g, '\n\n').trim().split('\n'),
(line, i) => <span>{line}<br /></span>
);
@sykwer
sykwer / perceptron_report.rb
Last active November 21, 2017 20:44
東大2年の簡単なパーセプトロンの課題
#! /usr/bin/env ruby
require "matrix"
# training data
v1 = [Vector[1, 3, 0], 1]
v2 = [Vector[1, 4, 3], 1]
v3 = [Vector[1, 6, 4], 1]
v4 = [Vector[1, 1, 2], 2]
v5 = [Vector[1, 3, 5], 2]
v6 = [Vector[1, 4, 6], 2]
@sykwer
sykwer / fetch_airbnb_reviews.js
Last active November 25, 2017 01:03
Airbnbのreviewデータをとってくる。使い方は下の方に。Airbnbのrooms#showページのhtml構造に深く依存しているコードなので2017/11/24現在以降正しく動く保証はありません。
const phantom = require("phantom")
const Papa = require("papaparse")
const fs = require("fs")
// input data
const dataRows = Papa.parse(fs.readFileSync("URLs.csv", "utf8")).data
dataRows.shift() // title row
const rowsCount = dataRows.length
// init model data
@sykwer
sykwer / pi_from_sectional_measurement.f90
Last active December 5, 2017 14:31
calculate pi by sectional measurement in multi threads.
program pi_from_sectional_measurement
!$ USE OMP_LIB
implicit none
!$ integer threads_count, thread_number
! Const
real(8), parameter :: pi25 = 3.141592653589793238462643D0
@sykwer
sykwer / ptag_in_contenteditable.js
Created December 8, 2017 13:55
In contenteEditable div, wrap row by p tag when press enter key.
const node = document.getElementById("contenteditable-id")
node.addEventListener("keypress", (e) => {
if (e.keyCode === 13) {
document.execCommand("formatBlock", false, "p")
}
})
// Wrap by h2 tag
// document.execCommand("formatBlock", false, "h2")
@sykwer
sykwer / MimesProject.java
Last active December 26, 2017 06:43
東大2年工学部システム創成B課題. マインスイーパーを解くプログラム.
import jp.ne.kuramae.torix.lecture.ms.core.MineSweeper;
import jp.ne.kuramae.torix.lecture.ms.core.Player;
public class MimesProject {
static public void main(String[] args) {
int gamesCount = 1000;
int clearedCount = 0;
for (int i = 0; i < gamesCount; i++) {
Player player = new MimesPlayer();

プログラミング基礎レポート

提出者

540377D 石川貴大 Mimesチーム

勝率

  • 初級: 76~79%
  • 中級: 54~57%
  • 上級: 12~14%

プログラムの構成

@sykwer
sykwer / how_with_works_in_python.py
Last active April 1, 2018 07:39
Simplest snippet that investigates how "with" works in Python.
class Klass:
def __init__(self):
print("instanciated")
def __del__(self):
print("gabage collected")
def __enter__(self):
print("__enter__")
return self
@sykwer
sykwer / MultithreadDemo.java
Created May 17, 2018 01:39
Multithread demo in Java.
public class MultithreadDemo {
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
Task task = new Task();
task.start();
}
}
}
class Task extends Thread {
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <dlfcn.h>
#include <stdio.h>
// #include <iostream>
using malloc_type = void*(*)(size_t);