Skip to content

Instantly share code, notes, and snippets.

@kaka-go
kaka-go / convert.sh
Last active November 6, 2021 00:46
Convert file encode
find ./folder/ -type f -name '*.php' | xargs file -i | grep unknown
iconv -f SHIFT-JIS -t UTF-8 ./folder_org/index.php > folder/index.php
find ./folder -type f | xargs -I '{}' echo 'iconv -f SHIFT-JIS -t UTF-8 {} > ../xxxx/{}'
@kaka-go
kaka-go / fetch.pl
Last active August 14, 2021 12:38
perl db connection and fetch data
use DBI;
$database="db_name";
$hostname="localhost";
$port="3306";
$user="xxx";
$password="xxx";
my $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";
my $dbh = DBI->connect($dsn, $user, $password, {mysql_enable_utf8 => 1});
my $sql = "select * from order limit 10";
@kaka-go
kaka-go / loop_date_range.py
Created April 12, 2021 08:26
Loop date range
import datetime
start_date = datetime.date(2020, 1, 1)
end_date = datetime.date(2020, 1, 4)
delta = datetime.timedelta(days=1)
while start_date <= end_date:
print(start_date)
start_date += delta
@kaka-go
kaka-go / find_dup.py
Last active July 26, 2020 07:09
find duplicate rows (jupyter)
import pandas as pd
df = pd.read_csv('data.csv', encoding='sjis')
df.head()
df_seq = df['some_seq_num']
df_seq_dup = df_seq[df_seq.duplicated()]
print(df_seq_dup)
@kaka-go
kaka-go / grep_unique.sh
Created July 3, 2020 03:10
grep unique occurrences (distinct search string)
# https://unix.stackexchange.com/questions/276741/using-grep-and-looking-for-unique-occurrences
grep --only-matching 'mapper \[.*\]' app.log | sort -u
@kaka-go
kaka-go / init.lua
Created June 11, 2020 14:49
hammerspoon auto input keystroke
-- hammerspoon config
hs.hotkey.bind({"ctrl", "alt"}, "Z", function()
-- hs.alert.show("Hello World!")
hs.eventtap.keyStrokes("some string you want to input")
end)
@kaka-go
kaka-go / create_event.py
Last active March 18, 2020 13:53
Get Object on Tencent Ketang, then create google events
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@kaka-go
kaka-go / log4j2.properties
Last active December 20, 2019 07:55
Delete log files older than 7 days (log4j, bash, logrotate)
# Delete log files older than 7 days
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.delete.type = Delete
appender.rolling.strategy.delete.basePath = ${sys:ls.logs}
appender.rolling.strategy.delete.maxDepth = 1
appender.rolling.strategy.delete.ifLastModified.type = IfLastModified
appender.rolling.strategy.delete.ifLastModified.age = 7d
@kaka-go
kaka-go / dp_robot_in_grid.py
Created November 2, 2019 03:18
robot move from top-left, to bottom right. (robot can move only right or down)
def getPath(grid):
if not grid or len(grid) == 0:
return []
R = len(grid)
C = len(grid[0])
path = []
memo = [[False]*C for i in range(R)] # memorization
calcPath(grid, R-1, C-1, path, memo)
@kaka-go
kaka-go / dijkstra_matrix.py
Created November 2, 2019 00:14
dijkstra algorithm matrix graph
# https://www.geeksforgeeks.org/printing-paths-dijkstras-shortest-path-algorithm/
#Class to represent a graph
class Graph:
# A utility function to find the
# vertex with minimum dist value, from
# the set of vertices still in queue
def minDistance(self,dist,queue):
# Initialize min value and min_index as -1