Skip to content

Instantly share code, notes, and snippets.

View t0yohei's full-sized avatar
👀
distracted

t0yohei t0yohei

👀
distracted
  • Tokyo
View GitHub Profile
@t0yohei
t0yohei / pattern_matching_fizz_buzz.rb
Created January 28, 2024 08:56
Ruby fizz buzz using pattern matching
def is_fizz(num:)
return num % 3 == 0 ? 0b1 : 0b0
end
def is_buzz(num:)
return num % 5 == 0 ? 0b1 : 0b0
end
def fizz_buzz(max:)
(1..max).each do |num|
@t0yohei
t0yohei / array_find.php
Last active June 8, 2022 02:19
array find(detect) in ruby to PHP
/**
* @param array $array
* @param callable $function
* @return null | array
*/
function array_find(array $array, callable $function)
{
$result = array_filter(
$array,
function ($item) use ($function) {
@t0yohei
t0yohei / text
Last active February 26, 2022 05:38
.git/info/exclude
.devcontainer/
Dockerfile
docker-compose.yml
@t0yohei
t0yohei / docker-compose.yml
Created February 12, 2022 11:03
docker-compose file for nuxt framework
version: '3.7'
services:
app:
build: .
ports:
- 3000:3000
command: "npx yarn play"
@t0yohei
t0yohei / Dockerfile
Last active February 26, 2022 05:11
Dockerfile nuxt framework
FROM node:latest
WORKDIR /usr/src/app
COPY . ./
RUN npx yarn install
RUN npx yarn stub
CMD ["/bin/bash"]
EXPOSE 3000
IRREGULAR_HASH = {"stop": "stopped", "go": "gone", "read": "read"}
VOWELS = ["a", "i", "u", "e", "o"]
def verb_past(str):
if IRREGULAR_HASH.get(str):
return IRREGULAR_HASH[str]
elif str[-1] == "y" and not str[-2] in VOWELS:
return str[:-1] + "ied"
elif str[-1] == "c":
@t0yohei
t0yohei / linked_list.rb
Last active June 27, 2021 15:20
Singly Linked List with ruby
class Node
def initialize(value, next_node = nil)
@value = value
@next_node = next_node
end
attr_reader :value
attr_accessor :next_node
end
@t0yohei
t0yohei / nl.py
Created June 26, 2021 06:47
unix `nl` command like code with python
# example: python nl.py fizz_buzz.py
import sys
def display_lines_with_number(lines):
i = 1
for line in lines:
# 改行コードの場合は、行番号を振らずに表示する
if line == "\n":
print(line, end="")
@t0yohei
t0yohei / fizz_buzz.py
Created June 26, 2021 05:36
fizzbuzz program without any `if`, `while`, `for` and relational operators such as `==`.
THREE_HASH = {0: "fizz", 1: "", 2: ""}
FIVE_HASH = {0: "buzz", 1: "", 2: "", 3: "", 4: "", 5: ""}
def fb(i):
result = ""
result += THREE_HASH[i % 3]
result += FIVE_HASH[i % 5]
return result
@t0yohei
t0yohei / fizz_buzz.py
Created June 12, 2021 01:03
Just simple fizz_buzz.py sample
def fb(n):
if n % 15 == 0:
return 'FizzBuzz'
elif n % 5 == 0:
return 'Buzz'
elif n % 3 == 0:
return 'Fizz'
return ''
i = 1