Skip to content

Instantly share code, notes, and snippets.

View thara's full-sized avatar
🎯
Focusing

Tomochika Hara thara

🎯
Focusing
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>GLTFLoader example</title>
<style>
body { margin: 0; overflow: hidden;}
</style>
</head>
<body>
// from https://stackoverflow.com/a/46049763
import Foundation
struct JSONCodingKeys: CodingKey {
var stringValue: String
init?(stringValue: String) {
self.stringValue = stringValue
}
@thara
thara / lifegame.go
Last active June 30, 2020 07:30
Conway's Game of Life written in Go
package main
import (
"fmt"
"time"
)
type Point struct {
x int
y int
@thara
thara / input.swift
Last active April 10, 2020 14:51
Read every character from stdin
import Foundation
let stdin = FileHandle.standardInput
var term = termios()
tcgetattr(stdin.fileDescriptor, &term)
term.c_lflag &= ~(UInt(ECHO | ICANON)) // Noecho & Noncanonical
tcsetattr(stdin.fileDescriptor, TCSAFLUSH, &term);
@thara
thara / lifegame.rs
Last active November 12, 2020 02:49
Conway's Game of Life written in Rust
use std::collections::HashSet;
use std::io::{self, stdout, Write};
type Point = (i8, i8);
type Board = HashSet<(i8, i8)>;
fn neighbors(point: Point) -> [Point; 8] {
let (x, y) = point;
[
(x + 1, y),
@thara
thara / lifegame.exs
Last active April 8, 2020 14:55
Conway's Game of Life written in Elixir
defmodule LifeGame do
def advance(board) do
board |> neighbors_all |> MapSet.to_list |> Enum.filter(&living?(&1, board)) |> MapSet.new
end
defp living?(point, board) do
count = point |> neighbors |> Enum.count(&MapSet.member?(board, &1))
count == 3 || (MapSet.member?(board, point) && count == 2)
end
@thara
thara / era-scraping.rs
Created January 12, 2020 04:33
Generate Japanese era list by scraping, for thara/erajp
use std::fs;
use std::io::{BufWriter, Write};
extern crate reqwest;
extern crate scraper;
use scraper::{Html, Selector};
extern crate encoding;
use encoding::all::EUC_JP;
use encoding::{DecoderTrap, Encoding};
@thara
thara / Package.swift
Last active December 23, 2019 12:26
Use libsoundio from Swift
// swift-tools-version:5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "SoundIOSample",
products: [
.executable(
name: "SoundIODemo",
targets: ["SoundIODemo"]),
@thara
thara / lifegame.swift
Last active April 10, 2020 16:54
Conway's Game of Life written in Swift, except classes; ported from https://gist.github.com/thara/ded6dd880ba95580088ef8875abb05e5
import Foundation
let height = 30
let width = 60
struct Point : Hashable {
var x: Int
var y: Int
}
@thara
thara / lifegame.rb
Last active March 22, 2020 08:31
Conway's Game of Life written in Ruby, except classes; ported from https://gist.github.com/thara/ded6dd880ba95580088ef8875abb05e5
require 'set'
def neighbors(point)
return to_enum(:neighbors, point).to_a unless block_given?
x, y = point
yield [x + 1, y]
yield [x - 1, y]
yield [x, y + 1]
yield [x, y - 1]
yield [x + 1, y + 1]