Skip to content

Instantly share code, notes, and snippets.

View caramelchocolate's full-sized avatar

caramelchocolate

View GitHub Profile
@caramelchocolate
caramelchocolate / main.sh
Created May 20, 2021 07:25
console clock
while;do sleep 3; printf "\r%s" $(date | awk '{print $1 $2 "_" $4 }'); done
@caramelchocolate
caramelchocolate / gist:1cf0c660d99482cf9f0f8b3aad6506fe
Last active January 16, 2021 17:55
Get local directory of Evernote notes from SQLite.
# SQLite path in Mac.
/Users/***/Library/Containers/com.evernote.Evernote/Data/Library/Application\ Support/com.evernote.Evernote/accounts/www.evernote.com/***/localNoteStore/LocalNoteStore.sqlite
# SQL
SELECT ZLOCALUUID FROM ZENNOTE WHERE ZGUID="foo";
<?php
# shell
# $ printf '\xF0\x9D\x95\x92'
# $ printf "𝕒"| hexdump
# f09d9592 𝕀
$start = 4036859264;
$end = 4036859281;
for ($i=$start; $i<$end; $i++) {
$hex = escape(dechex($i));
<?php
date_default_timezone_set('Asia/Tokyo');
$date = new DateTimeImmutable();
var_dump($date->format('Y-m-d H:i:s.u'));
var_dump($date->format('Y-m-d H:i:s.v'));
$date = new DateTimeImmutable('2020-04-20 11:12:13');
var_dump($date->format('U'));
var_dump(mktime($hour=11, $minute=12, $second=13, $month=4, $day=20, $year=2020));
?>
@caramelchocolate
caramelchocolate / include.php
Created May 7, 2020 06:18
include vs ob_get_clean benchmark
<?php
$time = microtime(true);
register_shutdown_function(
function () use ($time) {
$time = microtime(true) - $time;
$format = <<<EOD
Memory: %s / %s MB
Time: %f ms
EOD;
--TEST--
mail test
--INI--
sendmail_path=./stdout.sh
mail.add_x_header=off
mail.log=./mail.log
--FILE--
<?php
# pear run-tests mailtest.phpt
$to = 'example@example.com';
@caramelchocolate
caramelchocolate / main.php
Created April 9, 2020 14:45
Round-off error example
<?php
$a = 0.1 + 0.1 + 0.1;
$b = 0.3;
if ($a != $b) {
echo "Round-off error" . PHP_EOL;
}
$a = (0.1 * 0.1) * 30;
$b = 0.3;
if ($a != $b) {
<?php
# php -d register_argc_argv=0 main.php
var_dump(ini_get("register_argc_argv"));
$argv = [
__FILE__,
'-f',
'123',
];
var_dump(getopt('f:'));
?>
@caramelchocolate
caramelchocolate / main.sh
Created April 4, 2020 12:52
Write log to file
#!/bin/sh
dir_path="/path/"
date_str=$(date "+%Y%m%d_%H%M%S")
log_name="${dir_path}/${date_str}.log"
touch "${log_name}"
command 2>&1 | tee -a ${log_name};
# or
command >> "${log_name}" 2>&1
@caramelchocolate
caramelchocolate / main.sh
Created April 4, 2020 12:50
Run on a specific day.
#!/bin/sh
if [ `date +"%Y%m%d"` == "20200401" ]; then
# do something
:
fi