Skip to content

Instantly share code, notes, and snippets.

View yowcow's full-sized avatar
💮
Job well done

Yoko OYAMA yowcow

💮
Job well done
View GitHub Profile
@yowcow
yowcow / main_test.go
Created July 11, 2018 06:57
JSON unmarshal serial v. parallel
package main
import (
"encoding/json"
"sync"
"testing"
)
var jsonStr = `{"url":"http://hoge","score":123,"map":{"123":123,"234":234}}`
@yowcow
yowcow / add-disk-steps.txt
Last active July 1, 2018 07:39
Steps to add a fresh disk to running Linux
# List devices
fdisk -l
lsblk
fdisk /dev/mynewdevice
# Check device info
blkid /dev/mynewdevice
# Format the new device
mkfs.ext4 /dev/mynewdevice
@yowcow
yowcow / docker-dangling-images.sh
Created June 29, 2018 01:07
List dangling docker images
#!/bin/sh
# List dangling images
docker images --filter dangling=true
# List dangling image IDs
docker images --filter dangling=true | awk 'NR > 1 { print $3 }'
# Remove all dangling images
docker images --filter dangling=true | awk 'NR > 1 { print $3 }' | xargs docker rmi
@yowcow
yowcow / promise.js
Created June 15, 2018 07:49
A chain of Promises
const waits = [1, 2, 1, 2, 0, 1, 2, 1, 2];
const p = waits.reduce(
function (p, val) {
return p.then(function () {
return new Promise(function (resolve, reject) {
setTimeout(
function () {
if (val === 0) {
console.log(`${val} 秒は待てません`)
@yowcow
yowcow / flat-or-assoc.php
Created May 11, 2018 06:20
Flat array or assoc array
<?php
$try_count = 50000000;
$t0 = microtime(true);
for ($i = 0; $i < $try_count; $i++) {
$data1 = [
'EU', 'AD', 'AL', 'AT', 'BA', 'BE', 'BG', 'BY',
'CH', 'CS', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI',
@yowcow
yowcow / epoch.mk
Created February 22, 2018 01:34
Converting epoch second to date time, and vice versa
EPOCH = 0
DATE = 1970-01-01 00:00:00 JST
all:
now:
date
date +%s
date:
@yowcow
yowcow / cert.mk
Created February 2, 2018 01:05
Show SSL certificate
#
# https://serverfault.com/questions/661978/displaying-a-remote-ssl-certificate-details-using-cli-tools
#
HOST = github.com
PORT = 443
all:
echo | \
openssl s_client -showcerts -servername $(HOST) -connect $(HOST):$(PORT) 2>/dev/null | \
@yowcow
yowcow / bdb-cursor.c
Last active December 6, 2017 01:05
BerkeleyDB cursor in C
#include <stdio.h>
#include <string.h>
#include <db.h>
#define FILE "some.db"
int main() {
DBT key, data;
DBC *cursor;
DB *dbp;
@yowcow
yowcow / gist:a5b238ba1c3a2524e6e684d84e996f2f
Created December 2, 2017 05:14
Ubuntu GNOME processes
yowcow 1896 0.0 0.0 355808 7932 ? Sl Dec01 0:00 /usr/bin/gnome-keyring-daemon --daemonize --login
yowcow 1905 0.0 0.1 584264 17612 ? Ssl Dec01 0:00 /usr/lib/gnome-session/gnome-session-binary
yowcow 2017 0.0 0.0 11228 324 ? Ss Dec01 0:00 /usr/bin/ssh-agent /usr/bin/im-launch gnome-session
yowcow 2028 0.0 0.4 735224 77748 ? Sl Dec01 0:01 /usr/bin/gnome-screensaver --no-daemon
yowcow 2041 0.1 1.6 3943988 270740 ? Sl Dec01 1:15 /usr/bin/gnome-shell
yowcow 2196 0.0 0.0 614876 14552 ? Sl Dec01 0:00 /usr/lib/gnome-shell/gnome-shell-calendar-server
yowcow 2206 0.0 0.2 796656 33320 ? Sl Dec01 0:00 /usr/lib/gnome-online-accounts/goa-daemon
yowcow 2221 0.0 0.0 297168 7524 ? Sl Dec01 0:00 /usr/lib/gnome-online-accounts/goa-identity-service
yowcow 2279 0.0 0.0 272104 5776 ? Sl Dec01 0:00 /usr/lib/gnome-settings-daemon/gsd-mouse
yowcow 2284 0.0 0.1 823184 27856 ? Sl
@yowcow
yowcow / buffer_or_bufio.go
Created October 16, 2017 02:22
Buffer or Buffered IO, multiple times or at once
package main
import (
"bufio"
"bytes"
"fmt"
"io"
"testing"
)