Hatena::ブログ(Diary)

satoru.netの自由帳 このページをアンテナに追加 RSSフィード

181220Thuday

順番が変になったカラムを特定のキー順に振りなおしてやりなおせるSQL

ALTER TABLE `subject` CHANGE num num int(11) NOT NULL;

alter table subject drop primary key;

SET @i := 0; UPDATE subject SET num = (@i := @i +1) ORDER BY created;

ALTER TABLE subject CHANGE num num int auto_increment, ADD PRIMARY KEY(num);

ALTER TABLE subject AUTO_INCREMENT = @i;

実行は一瞬

180112Friday

coincheck-API perl

#!/usr/bin/perl

use HTTP::Tiny;
use Digest::SHA qw/hmac_sha256_hex/;
use strict;

my $ACCESS_KEY = ACCESS_KEY;
my $SECRET_KEY = SECRET_KEY;

my $dt = time*10000;
my $url = "https://coincheck.com/api/ticker";
my $signature = hmac_sha256_hex($dt . $url ,$SECRET_KEY);
my $tiny = new HTTP::Tiny(
	default_headers => {
		"ACCESS-KEY" => $ACCESS_KEY,
		"ACCESS-NONCE"=> $dt,
		"ACCESS-SIGNATURE"=> $signature,
	}
);

my $res = $tiny->get("$url");
print $res->{content};

160525Wedday

memo

#!/usr/bin/perl

use re 'eval';

my $key = "192.168.[0-100].*";
my $re = make_re($key);

print "[$re]\n";

my @lines = grep {$_} split /\n/,qq{
192.168.99.112 - - [10/Jul/2013:13:53:15 +0900] "GET /top.html HTTP/1.1" 404 1426 "http://facebook.com" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36"
192.168.81.20 - - [10/Jul/2013:15:06:33 +0900] "GET /hogehoge.html HTTP/1.1" 404 4374 "http://paiza.jp" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36"
192.168.223.58 - - [10/Jul/2013:21:32:01 +0900] "GET /hoge.html HTTP/1.1" 304 6601 "http://paiza.jp" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:22.0) Gecko/20100101 Firefox/22.0"
};

for(@lines){
	if(m@^$re@){
		s@\[|\]@@gim;
		my($ip,$date,$file) = (split / /)[0,3,6];
		print "$ip $date $file\n";
	}
}

sub make_re{

	my $pattern = shift;

	my @re;
	my $count = 1;

	for my $n ($pattern =~ m@([^\.]+)@g){
		if($n =~ m@\[@){ # レンジ指定
			my @n = $n =~ m@(\d+)@gim;
			push @re,sprintf '(\d+)(?(?{range($%s,%s,%s)})|(?!))',$count,$n[0],$n[1];
			$count++;
		} elsif($n eq "*") { #アスタリスク
			push @re,'\d+';
		} else { #数値
			push @re,"$n";
		}
	}
	return join('\.',@re);
}

sub range{
	my ($n,$min,$max) = @_;
	return ($n >= $min && $n <= $max)
}

160312Satday

CloudFlareのmod_cloudflareのupdate

確認

ls -al /etc/httpd/conf.d/cloudflare.conf

更新

sudo rpm --import http://pkg.cloudflare.com/pubkey.gpg
yum update mod_cloudflare

ip情報

https://www.cloudflare.com/ips/

https://www.cloudflare.com/ips-v4

https://www.cloudflare.com/ips-v6

160109Satday

swift / 永続的に保存できるlocalStrage的なやつ

var cacheKey:String = "dataKey";

let userData = NSUserDefaults.standardUserDefaults();

value:Int = userData.integerForKey(cacheKey);

userData.setInteger(value+1, forKey: cacheKey)

print("value:\(value)");

©satoru.net
Mail Twitter