Skip to content

Instantly share code, notes, and snippets.

@doloopwhile
doloopwhile / gist:8c6ec7dd4703e8a44e559411cb2ea221
Last active April 11, 2024 00:00
Why I decided to discontinue PyExecJS and Python-CoffeeScript ?

What is PyExecJS and Python-CoffeeScript.

They are Python libraries that I developped on 2011.

  • PyExecJS: Automatically picks the best runtime available to evaluate your JavaScript program.
  • Python-CoffeeScript: A bridge to the JS CoffeeScript compiler.

They are ports of ruby gems with same name (execjs and ruby-coffee-script).

The aim of them were to compile CoffeeScript code on Windows XP.

@doloopwhile
doloopwhile / gist:e808ddafe76f0dcefeee
Last active March 11, 2024 02:26
302 Found / 303 See Other / 307 Temporary Redirect

3つのリダイレクトの違い

実はGET(とHEAD)でリクエストされた時の動作は変わりません。 違いはPOST(やPUT/DELETE/OPTIONS)でリクエストされた時の動作です。

**"307 Temporary Redirect(一時的リダイレクト)"**は最初のURLでは実際の処理は行わず、リダイレクト先に改めてリクエストを出し直して欲しい時に使います。 したがって、最初のリクエストがPOSTであれば、 ブラウザはリダイレクト先にもPOSTを使います。 "301 Moved Permanently(恒久的リダイレクト)"の「一時的」版であると思えばよいでしょう。

@doloopwhile
doloopwhile / git-fixup-peco
Last active July 14, 2023 06:43
git-fixup-peco: select fixup target with peco
#!/bin/bash
set -o pipefail
set -e
HASH=$(git log --oneline | peco | cut -d " " -f 1)
if [ "$?" -ne 0 -o -z "$HASH" ]; then
exit 1
fi
git commit --fixup "$HASH" $@
# install:
@doloopwhile
doloopwhile / .bashrc
Created November 1, 2018 05:03
The ultimate script to indicate git status on PS1
#!/bin/bash
# PS1の設定
C() {
case $1 in
black) echo -e -n "\033[1;30m";;
red) echo -e -n "\033[1;31m";;
green) echo -e -n "\033[1;32m";;
yellow) echo -e -n "\033[1;33m";;
blue) echo -e -n "\033[1;34m";;
@doloopwhile
doloopwhile / qiita.ipynb
Created October 17, 2019 03:08
自分が投稿したQiita記事のLike数・View数を収集する
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@doloopwhile
doloopwhile / gist:1419f460fbe2c3561714a4cd3a20c390
Last active October 11, 2019 02:51
Variable width bytes representation of uint64_t
'''
Variable width bytes representation of uint64_t.
Inspired by Ruby interpreter。
https://techlife.cookpad.com/entry/2019/09/26/143000
> 0x0000000000000000 - 0x000000000000007f: 1byte | 1XXXXXXX |
> 0x0000000000000080 - 0x0000000000003fff: 2bytes | 01XXXXXX | XXXXXXXX |
> 0x0000000000004000 - 0x00000000001fffff: 3bytes | 001XXXXX | XXXXXXXX | XXXXXXXX |
> 0x0000000000020000 - 0x000000000fffffff: 4bytes | 0001XXXX | XXXXXXXX | XXXXXXXX | XXXXXXXX |
@doloopwhile
doloopwhile / file0.rb
Created September 26, 2018 12:21
active_job / delayed_job を高速化するハック ref: https://qiita.com/tonluqclml/items/f6a0411a8fbe3031cb0d
class CsvFormController < ApplicationController
# 「名前・年齢・メールアドレス」のCSVファイルをアップロードして、Userを作れる画面
#
# 太郎,32,taro@example.com
# 二郎,30,jiro@example.com
# 三郎,27,sabu@example.com
def upload
rows = CSV.parse(params[:file].read)
UserUploadJob.perform_later(rows: rows)
end
@doloopwhile
doloopwhile / file0.txt
Created September 14, 2018 02:20
Git 管理下のファイルを一括置換する git-sed コマンドを作った ref: https://qiita.com/tonluqclml/items/13b323cea92425b85218
$ git ls-files | xargs -n 1 sed -i 's|find_by_admin|find_by(type: :admin)|g'
@doloopwhile
doloopwhile / git-sed
Created September 14, 2018 02:16
git-sed command
#!/bin/bash
set -euC
if [ "$#" -eq 0 ]; then
echo 'git sed COMMAND [PATH [PATH[...]]]' >&2
exit 1
fi
if which gsed > /dev/null; then
SED=gsed # for macOS
else
import sys
import csv
import pandas as pd
from pprint import pprint
from sklearn import linear_model
from sklearn import svm
from sklearn.preprocessing import StandardScaler
def read_csv(filename):
df = pd.read_csv(filename)