Skip to content

Instantly share code, notes, and snippets.

@quanon
quanon / count_characters.js
Created July 4, 2017 06:10
文章の文字数を、改行や空白文字などを除いてカウントする。
/* @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
@quanon
quanon / rsa.py
Last active May 22, 2017 15:47
公開鍵暗号アルゴリズム RSA を使って実際に暗号化してみる (Python 編)
from fractions import gcd
def lcm(p, q):
'''
最小公倍数を求める。
'''
return (p * q) // gcd(p, q)
@quanon
quanon / hoge_spec.rb
Last active September 14, 2022 08:48
RSpec での例外処理について
class Hoge
class InvalidBlockError < StandardError; end
attr_accessor :result, :error
# 渡されたブロックを実行して、結果をプロパティに格納するインスタンスメソッド。
def call
yield
self.result = :success
rescue => e
@quanon
quanon / kana.txt
Last active May 16, 2017 14:24
巨大なテキストファイルを最終行から each_line する
あいうえお
かきくけこ
さしすせそ
たちつてと
なにぬねの
はひふへほ
まみむめも
や ゆ よ
らりるれろ
わ   を
@quanon
quanon / lazy.rb
Created May 16, 2017 09:51
lazy or not lazy
# 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
@quanon
quanon / lazy.rb
Last active May 15, 2017 13:55
Enumerator::Lazy
[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
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
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()
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)
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)