Instantly share code, notes, and snippets.

View luhn_test.go
package luhn
import (
"strconv"
"strings"
"testing"
)
type testCase struct {
input string
View luhn.go
package luhn
func IsValid(digits []int) bool {
sum := 0
alt := false
for i := len(digits) - 1; 0 <= i; i-- {
d := digits[i]
if alt {
d *= 2
if d > 9 {
View apple_ranking.py
import requests
import json
url = 'https://itunes.apple.com/jp/rss/topgrossingapplications/limit={}/{}'
result = requests.get(url.format(10, 'json')).json()
for i, x in enumerate(result['feed']['entry'], 1):
print(i, x['im:name']['label'])
View anagram.py
def is_anagram1(s1, s2):
if len(s1) != len(s2):
return False
return sorted(list(s1)) == sorted(list(s2))
def is_anagram2(s1, s2):
if len(s1) != len(s2):
return False
View apple_soup.py
import MySQLdb
import urllib.request
from bs4 import BeautifulSoup
from datetime import datetime
rss_url = 'https://itunes.apple.com/jp/rss/topgrossingapplications/limit={rank_limit}/{rss_format}'
rank_limit = 200
rss_format = 'xml'
current_date = datetime.now().strftime("%Y%m%d")
View script.sh
#!/usr/bin/env bash
# set -eu
sudo localedef -f UTF-8 -i ja_JP ja_JP
echo "Asia/Tokyo" | sudo tee /etc/timezone
sudo dpkg-reconfigure --frontend noninteractive tzdata
sudo apt-get -y install zlib1g-dev libssl-dev libreadline-dev \
libsqlite3-dev libbz2-dev libncurses5-dev libgdbm-dev liblzma-dev tk-dev zlibc
View VagrantFile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "debian/jessie64"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.synced_folder "./src/" , "/home/vagrant/src"
config.vm.provision "shell" do |s|
s.path = "provisioning/script.sh"
View problem1.py
def sum_for(arg):
total = 0
for i in arg:
total += i
return total
def sum_while(arg):
total = cnt = 0
while cnt < len(arg):
View Dockerfile
FROM debian:latest
RUN apt-get update
RUN apt-get install -y --no-install-recommends \
git tig vim \
python3 python-dev python-pip python-virtualenv
View Effective Python.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.