Skip to content

Instantly share code, notes, and snippets.

View peketamin's full-sized avatar
🐔
Hello world!

Yuki Yokoyama peketamin

🐔
Hello world!
View GitHub Profile
@peketamin
peketamin / init.vim
Last active January 25, 2020 03:32
neovim config: ~/.config/nvim/init.vim
" set
"set mouse=a
set mouse=
set number
set list
set listchars=tab:»-,trail:-,eol:↲,extends:»,precedes:«,nbsp:%
set expandtab
set tabstop=4
set softtabstop=4
set shiftwidth=0
@peketamin
peketamin / mojibake_taisaku.sh
Created September 25, 2019 03:20
bash_profile setting for mojibake taisaku
# source .bashrc
test -r ~/.bashrc && . ~/.bashrc
# LANG
export LANG=en_US.UTF-8
export LC_ALL=$LANG
@peketamin
peketamin / psycopg2_on_macos_mojave.md
Last active September 5, 2019 11:39
psycopg2 installing error on mac OS Mojave

brew install postgresql@9.6 brew install openssl

update ~/.bash_profile following the instraction that shows after installation above.

poetry install

@peketamin
peketamin / requests_post_with_csrf.py
Last active July 25, 2019 09:22
requests_post_with_csrf.py
import requests
url = 'http://localhost:8000/xxx/unsubscribe/xxx'
session = requests.session()
res_get = session.get(url)
resp_post = session.post(
url,
data={"csrfmiddlewaretoken" : session.cookies['csrftoken']},
headers={'referer': url}
@peketamin
peketamin / generate_user_list.md
Last active July 21, 2019 10:14
ユーザーレコードをDBから読み込んでCSVを出力するクラスを作る、というお題に対して、どうオブジェクト指向で実装するか (Python)

ユーザーレコードをDBから読み込んでCSVを出力するクラスを作る、というお題に対して、どうオブジェクト指向で実装するか (Python)

手続き指向での提出例

import datetime
from typing import Dict, List

import pandas as pd
@peketamin
peketamin / cumsum.py
Created July 20, 2019 02:42
Cumulative sum in Python
def sum(l: list):
if not l:
return 0
i = l.pop()
return sum(l) + i
print(sum([1,2,3,4,5]))
# 15
@peketamin
peketamin / class_like_obj.js
Created July 8, 2019 08:11
Lightweight ES5 class like object definition
var Person = {
init: function() {
this.first_name = '';
this.last_name = '';
return this;
},
getFullName: function() {
return this.first_name + ' ' + this.last_name;
},
};
@peketamin
peketamin / q_json.sql
Last active May 11, 2019 08:36
PostgreSQL: JSON query example
-- https://www.postgresql.org/docs/9.5/functions-json.html
WITH
virtual_table AS (SELECT key, value FROM jsonb_each('{"k": {"sub_key": 10}, "k2": {"sub_key": 20}}')),
extracted_values AS (SELECT value->'sub_key' AS sub_key FROM virtual_table)
SELECT * FROM extracted_values
@peketamin
peketamin / test_thread.py
Created May 10, 2019 13:31
Thread and BoundedSemaphore
import time
from threading import Thread, BoundedSemaphore
MAX_CONCURRENT_THREADS = 3
thread_limiter = BoundedSemaphore(value=MAX_CONCURRENT_THREADS)
class MyThread(Thread):
def run(self):
thread_limiter.acquire()
@peketamin
peketamin / slack_notification.py
Created April 24, 2019 03:23
Slack notification
"""Slack notification
This needs:
- requests==2.11.1
- slackclient==1.3.1
"""
import logging
import os
from socket import gethostname