Skip to content

Instantly share code, notes, and snippets.

@quanon
quanon / curry.md
Last active September 26, 2017 15:19
福岡のおすすめカレー
@quanon
quanon / magica.html
Last active September 11, 2017 13:43
Sample HTML for WeasyPrint
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>魔法少女まどか☆マギカ</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/7.0.0/normalize.css">
<style>
html {
font-size: 62.5%;
@quanon
quanon / gh_issue_link.js
Last active August 31, 2017 07:35
GitHub Issue Link for Markdown
@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