This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* @flow */ | |
import { ucs2 } from 'punycode'; | |
export default (string: string): number => { | |
if (!string) return 0; | |
const processedString: string = | |
string | |
.trim() | |
.replace(/[\n\r\s\u200B]+/g, ''); // U+200B: ZERO WIDTH SPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fractions import gcd | |
def lcm(p, q): | |
''' | |
最小公倍数を求める。 | |
''' | |
return (p * q) // gcd(p, q) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hoge | |
class InvalidBlockError < StandardError; end | |
attr_accessor :result, :error | |
# 渡されたブロックを実行して、結果をプロパティに格納するインスタンスメソッド。 | |
def call | |
yield | |
self.result = :success | |
rescue => e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
あいうえお | |
かきくけこ | |
さしすせそ | |
たちつてと | |
なにぬねの | |
はひふへほ | |
まみむめも | |
や ゆ よ | |
らりるれろ | |
わ を |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'memory_profiler' | |
require 'resolv' | |
report = MemoryProfiler.report do | |
# $ wc -l development.log | |
# 1000000 development.log | |
open('development.log') do |f| | |
f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1] pry(main)> (1..10).map { |i| (i ** 2).tap(&method(:p)) }.map { |i| i.to_s.tap(&method(:p)) } | |
1 | |
4 | |
9 | |
16 | |
25 | |
36 | |
49 | |
64 | |
81 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
def with_serval(function): | |
@wraps(function) | |
def wrapper(*args, **kwargs): | |
print(f'サーバル「わたしはサーバルキャットのサーバル!この子は{args[0]}ちゃん」') | |
result = function(*args, **kwargs) | |
print(f'サーバル「{args[0]}ちゃんはすごいんだよ!」') | |
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
import sys | |
import time | |
from urllib.request import urlretrieve | |
channel = sys.argv[1] | |
with open(f'{channel}.txt', 'rt') as f: | |
lines = f.readlines() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import time | |
from selenium import webdriver | |
channel = sys.argv[1] | |
driver = webdriver.Chrome() | |
url = os.path.join('https://www.youtube.com/user', channel, 'videos') | |
driver.get(url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import tensorflow as tf | |
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' | |
filename_queue = tf.train.string_input_producer( | |
tf.train.match_filenames_once('./images/ズワイガニ/*.jpg')) | |
reader = tf.WholeFileReader() | |
_, value = reader.read(filename_queue) |