Skip to content

Instantly share code, notes, and snippets.

@tknhs
tknhs / flatten.py
Created November 26, 2013 16:42
多次元配列を平坦化(python2.6以降.python3では廃止)
from compiler.ast import flatten
flatten([0, [1, 2], [3, 4, [5, 6]], 7])
@tknhs
tknhs / permutations.py
Created November 26, 2013 16:46
順列生成
from itertools import permutations
[i for i in permutations(range(0, 2))]
#!/bin/bash
current_dir=$(cd $(dirname $0) && pwd)
export THEOS=/opt/theos
# clone theos.git
cd /opt
git clone git://github.com/DHowett/theos.git
# clone iphoneheaders.git
cd $THEOS
@tknhs
tknhs / extract_dict.py
Created February 19, 2014 16:15
Extract the duplicate values from dictionary
from collections import Counter
my_dict = {'F': 200, 'G': 500, 'D': 100, 'E': 400, 'B': 200, 'C': 300, 'A': 500}
# duplicate values list
dup_list = [k for k, v in Counter(my_dict.values()).items() if v > 1] # [200, 500]
print({k: v for k, v in my_dict.items() if v in dup_list}) # {'F': 200, 'G': 500, 'B': 200, 'A': 500}
@tknhs
tknhs / leap_year.py
Last active August 29, 2015 14:02
うるう年チェック
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# if文禁止
print([i%j == 0 for i, j in zip([int(input())]*3, [4, 100, 400])].count(True) % 2 == 1)
# if文・for文禁止
print(sum(list(map(lambda x, y: x%y == 0, [int(input())]*3, [4, 100, 400]))) % 2 == 1)
@tknhs
tknhs / FizzBuzz.py
Created August 25, 2014 23:39
FizzBuzz
# output: 1 - 100
# don't use "if" and "for"
print "\n".join(map(lambda x: [["FizzBuzz", "Fizz"], ["Buzz", str(x)]][bool(x%3)][bool(x%5)], range(1, 101)))
@tknhs
tknhs / fileencoding_checker.sh
Last active May 17, 2020 17:39
拡張子.mqh がバイナリファイルとして扱われることを防ぐために .git/hooks/pre-commit でコミットしていいかチェックする
#!/bin/bash
ok=true
for file in $(git diff --name-only --cached | grep .mqh); do
if [ "`nkf --guess $file | grep 'Shift_JIS'`" ]; then
:
else
ok=false
echo "$file is not Shift_JIS"
fi
@tknhs
tknhs / install_tmux.sh
Last active April 22, 2022 17:14
for Amazon Linux 2
LIBEVENT_VERSION="2.1.12-stable"
TMUX_VERSION="3.2a"
sudo yum install -y gcc kernel-devel make ncurses-devel openssl-devel
curl -LOk https://github.com/libevent/libevent/releases/download/release-${LIBEVENT_VERSION}/libevent-${LIBEVENT_VERSION}.tar.gz
tar -xf libevent-${LIBEVENT_VERSION}.tar.gz
cd libevent-${LIBEVENT_VERSION}
./configure --prefix=/usr/local
make -j4
PECO_VERSION="v0.5.11"
curl -LOk https://github.com/peco/peco/releases/download/${PECO_VERSION}/peco_linux_amd64.tar.gz
tar -xf peco_linux_amd64.tar.gz
sudo chmod +x peco_linux_amd64/peco
sudo cp peco_linux_amd64/peco /usr/local/bin/peco
@tknhs
tknhs / windows_update_switcher.ps1
Created March 13, 2022 01:27
Windows Updateの有効/無効化を実施して更新する
$windows_module_installer = "TrustedInstaller"
$windows_update = "wuauserv"
Get-Service -Name $windows_module_installer
Get-Service -Name $windows_update
$answer = (Read-Host "Windows Update 有効化/無効化 (e/d)")
if($answer -eq "e"){
Set-Service -Name $windows_module_installer -StartupType "Manual"