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
use strict;
use warnings;
use Benchmark qw(cmpthese);
my @keys = 1 .. 20;
my %key_map = map { $_ => 1 } @keys;
cmpthese(
5_000_000,
{ 'with grep()' => sub {
@yowcow
yowcow / grep-vs-hash.pl
Created April 19, 2017 09:50
grep vs. hash (worst case)
use strict;
use warnings;
use Benchmark qw(cmpthese);
my @keys = 1 .. 20;
my %key_map = map { $_ => 1 } @keys;
cmpthese(
5_000_000,
{ 'with grep()' => sub {
@yowcow
yowcow / psgi-response.pl
Last active April 18, 2017 10:28
Bare PSGI array-ref vs. Plack::Response
use strict;
use warnings;
use Benchmark qw(cmpthese);
use HTTP::Message::PSGI;
use HTTP::Request::Common;
use Plack::Response;
use Plack::Test;
my $app_with_plack_response = sub {
my $res = Plack::Response->new(200);
@yowcow
yowcow / install-local-tmux.sh
Created February 20, 2017 03:27
Install tmux locally
curl -LO http://ftp.gnu.org/gnu/ncurses/ncurses-6.0.tar.gz
curl -LO https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz
curl -LO https://github.com/tmux/tmux/releases/download/2.3/tmux-2.3.tar.gz
tar xzf ncurses-6.0.tar.gz && \
cd ncurses-6.0 && \
./configure --prefix $HOME/local && \
make && make install && \
cd ..
@yowcow
yowcow / request-test.js
Last active February 14, 2017 10:54
Simple HTTP client testing
import assert from "assert"
import co from "co"
import http from "http"
import request from "request"
describe("request", () => {
it("should make a GET request", () => co(function *() {
const server = http.createServer((req, res) => res.end("あばば"))
server.listen(5000)
@yowcow
yowcow / array-of-arrays.js
Created February 3, 2017 13:26
Reduce an array into array of arrays
const expect = require('expect')
const groupItems = (array = [], count) =>
array.reduce(
(prev, cur) => {
const lastIndex = prev.length - 1
return lastIndex === -1 ? [[cur]]
: prev[lastIndex].length === count ? [...prev, [cur]]
: [...prev.slice(0, -1), [...prev[lastIndex], cur]]
},
@yowcow
yowcow / promise-square.js
Created February 3, 2017 11:20
Square a set of numbers at a time
const sliceTodos = todos =>
todos.length <= 3
? [todos, []]
: [todos.slice(0, 3), todos.slice(3)]
const square = (x, callback) =>
setTimeout(() => callback(x ** 2), 1000)
const squarePromise = x =>
new Promise(resolve => square(x, res => resolve(res)))
@yowcow
yowcow / colored-output.sh
Last active January 27, 2017 10:05
Shell Colors
#!/bin/bash
# Colors:
# 1: Red
# 2: Greed
# 3: Yellow
# 4: Blue
# 5: Magenta
# 6: Cyan
# 7: White
@yowcow
yowcow / mongodump.sh
Created January 16, 2017 03:21
Dump MongoDB database
mongodump --port <PORT like 27018> --db <DATABASE> --collection <COLLECTION>
@yowcow
yowcow / letsencrypt.sh
Last active January 9, 2017 09:53
letsencrypt create/renew
# Create a certificate
sudo letsencrypt certonly --webroot \ ~
-w /srv/path/to/document/root \
-d my.working.fqdn
# Help on renew. See Also: https://certbot.eff.org/docs/using.html#re-running-certbot
letsencrypt --help renew
# Update created certificates
sudo letsencrypt renew --agree-tos \