Skip to content

Instantly share code, notes, and snippets.

View recuraki's full-sized avatar

Akira KANAI recuraki

View GitHub Profile
@recuraki
recuraki / hello.sh
Created October 20, 2013 09:41
test
#!/bin/sh
echo "hello"
@recuraki
recuraki / RandomString.py
Created October 22, 2013 08:32
任意の単語が出るまでがんばる。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
def RandomCharByString(stInput = None):
if stInput == None:
yield False
liInput = list(stInput)
while True:
var fb = Observable.Range(1, 100).Publish();
fb.Where(c1 => c1 % 3 == 0).Subscribe(c1 => Console.WriteLine("Fizz"));
fb.Where(c2 => c2 % 5 == 0).Subscribe(c2 => Console.WriteLine("Buzz"));
fb.Where(c3 => c3 % 3 != 0 && c3 % 5 != 0).Subscribe(c3 => Console.WriteLine(c3.ToString()));
fb.Connect();
var fb2 = new Subject<int>();
fb2.Where(c1 => c1 % 3 == 0).Subscribe(c1 => Console.WriteLine("Fizz"));
fb2.Where(c2 => c2 % 5 == 0).Subscribe(c2 => Console.WriteLine("Buzz"));
fb2.Where(c3 => c3 % 3 != 0 && c3 % 5 != 0).Subscribe(c3 => Console.WriteLine(c3.ToString()));
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Diagnostics;
namespace CiscoDiff
{
l = [100,200,201,202,203,301,303,305,306,401,402,403,405,501,502,601,602,603,701]
#これを
# [[701, 603, 602, 601, 502, 501, 405, 403, 402], [401, 306, 305, 303, 301, 203, 202, 201, 200], [100]]
#こうしたい
from itertools import zip_longest
#########################################
# zipすると端数分が消されちゃう
# [[100, 200, 201, 202, 203, 301, 303, 305, 306], [401, 402, 403, 405, 501, 502, 601, 602, 603]]
l = [100,200,201,202,203,301,303,305,306,401,402,403,405,501,502,601,602,603,701]
"""
下の4つについてtimeitしたけど、どう考えても、
r,s = s[:9], s[9:]
が早いです。本当にありがとうございました。
2.260901534450575
6.795336202391907
1.9528116482399511
9.414626154138594
"""
#!/usr/bin/python
l = [100,200,201,202,203,301,303,305,306,401,402,403,405,501,502,601,602,603,701]
# [[100, 200, 201, 202, 203, 301, 303, 305], [401, 402, 403, 405, 501, 502, 601, 602], [701]]
def f(s, l = 9):
i = 0
for i in range(len(s) / l):
yield s[l * i:l * i + 8]
yield s[l * (i + 1): len(s)]
print([x for x in f(l)])
@recuraki
recuraki / traceas.sh
Last active September 3, 2020 08:44
tracerouteにas nameを追加するやつ。
aslookup () {
if test `echo $1 | grep "^[0-9]*$" | wc -l ` = "1"
then
whois -h whois.cymru.com AS$1 | grep -v "AS Name" | cut -d " " -f 1
else
whois -h whois.cymru.com $1 | grep -v "AS Name"
fi
}
traceasnum () {
tf1=`mktemp /tmp/XXXXXX `
@recuraki
recuraki / fizzbuzz.js
Created May 19, 2017 16:00
fizzbuzz.js
// need rx.all.js
let source = Rx.Observable.range(1, 100);
let hot = source.publish();
hot.where(function (c) {
return c % 3 === 0;
}).subscribe(function (e) {
console.log("Fizz")
})
@recuraki
recuraki / addr.py
Created June 20, 2017 13:24
dictはsetで引き算できないので、一回、tupleにしてからsetで演算してdictに戻すテスト
# dictはsetで引き算できないので、一回、tupleにしてからsetで演算してdictに戻すテスト
before = [{'netmask': '32', 'ipAddr': '192.168.0.1'}, {'netmask': '32', 'ipAddr': '213.199.128.119'}]
after = [{'netmask': '32', 'ipAddr': '192.168.0.1'}, ]
print("before: {0}".format(before))
print("after: {0}".format(after))
#before: [{'netmask': '32', 'ipAddr': '192.168.0.1'}, {'netmask': '32', 'ipAddr': '213.199.128.119'}]
#after: [{'netmask': '32', 'ipAddr': '192.168.0.1'}]
addrList2addrTuple = lambda x: (x["netmask"], x["ipAddr"])