This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- from decimal biginteger to hexdecimal text with any separator | |
CREATE OR REPLACE FUNCTION serialnumber_hex(serial bigint, sep varchar) RETURNS varchar AS $$ | |
DECLARE | |
org varchar := ''; | |
res varchar := ''; | |
BEGIN | |
org := to_hex(serial); | |
WHILE 0 < length(org) LOOP | |
res := concat_ws(sep, res, substr(org, 1, 2)); | |
org := substr(org, 3, length(org)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File | |
import java.net.InetAddress | |
import com.maxmind.geoip2.DatabaseReader.Builder | |
import com.maxmind.geoip2.exception.AddressNotFoundException | |
object GeoipSample { | |
def main(args: Array[String]): Unit ={ | |
val database = new File("/tmp/GeoLite2-Country.mmdb") | |
// This creates the DatabaseReader object, which should be reused across lookups. | |
val reader = new Builder(database).build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.service | |
import scala.io.Source | |
import scala.util.parsing.combinator.RegexParsers | |
object CloudFlareLogParserService { | |
def resolve: Unit = { | |
val accessLog = | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[inet_http_server] ; inet (TCP) server disabled by default | |
port=127.0.0.1:9001 ; (ip_address:port specifier, *:port for all iface) | |
;username=user ; (default is no username (open server)) | |
;password=123 ; (default is no password (open server)) | |
[include] | |
files = conf.d/*.ini |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python | |
# coding:utf-8 | |
import csv | |
import sys | |
""" | |
根ノードから再帰的に深さ優先で木構造を作成しつつ探索も行う。 | |
コスト集計も中途で行い、最低コストを上回った時点で以降の子孫ノードの探索を中止する。 | |
木構造のプログラムを書くのに慣れていないため、実直にコーディングした。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> s = [('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)] | |
>>> d = defaultdict(list) | |
>>> for k, v in s: | |
... d[k].append(v) | |
... | |
>>> d.items() | |
[('blue', [2, 4]), ('red', [1]), ('yellow', [1, 3])] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Animal | |
def initialize(species) | |
@species = species | |
end | |
def bark() | |
"bowbow" | |
end | |
def mew() | |
"mewwww" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Animal | |
def initialize(species) | |
@species = species | |
end | |
def bark() | |
"bowbow" | |
end | |
def mew() | |
"mewwww" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function run-ec2 { | |
source ~/.virtualenv/CP-2710/bin/activate | |
aws ec2 run-instances --image-id $1 --instance-type t1.micro --key-name oregon > /tmp/run-i | |
aws_id=$(cat /tmp/run-i | jq -r '.Instances | .[] | .InstanceId') | |
echo "aws_id: $aws_id" | |
sleep 10 | |
aws ec2 describe-instances --instance-ids $aws_id > /tmp/run-i | |
aws_ip=$(cat /tmp/run-i | jq -r '.Reservations | .[] | .Instances | .[] | .PublicDnsName') | |
echo "aws_ip: $aws_ip" | |
echo 'ssh -i ~/.ssh/id_rsa.aws.oregon -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ec2-user@$aws_ip' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
read USER_NAME | |
useradd ${USER_NAME} | |
mkdir -m 700 /home/${USER_NAME}/.ssh | |
cat << _EOF_ > /home/${USER_NAME}/.ssh/authorized_keys | |
chmod 400 /home/${USER_NAME}/.ssh/authorized_keys | |
chown ${USER_NAME}:${USER_NAME} -R /home/${USER_NAME}/.ssh |
OlderNewer