Skip to content

Instantly share code, notes, and snippets.

@Genki-S
Genki-S / auto-ssh-agent-start-and-kill.sh
Last active January 8, 2020 05:20
Automatically start ssh-agent when necessary, and kill ssh-agent when ssh is done (to not leave many ssh-agent processes around)
ssh() {
if [ -z "$SSH_AGENT_PID" ]; then
eval "$(ssh-agent -s)"
# ssh-add OTHER_KEYS
fi
command ssh $@
kill $SSH_AGENT_PID
unset SSH_AGENT_PID
}
//
// ViewController.m
// ScienceHackDay
//
// Created by Genki Sugimoto on 24/10/2015.
// Copyright © 2015 Genki Sugimoto. All rights reserved.
//
#import "ViewController.h"
require 'sinatra'
require 'json'
require 'droplet_kit'
DO_TOKEN = 'YOUR_TOKEN'
DATA_JSON_FILE = './data.json'
set :bind, '0.0.0.0'
def do_client
@Genki-S
Genki-S / docker.zsh
Created June 2, 2015 23:57
boot2docker wrapper
function docker() {
local st
st=$(boot2docker status)
if [ "$st" != "running" ]; then
boot2docker start
fi
if [ -z "$DOCKER_HOST" ]; then
$(boot2docker shellinit)
fi
command docker "$@"
@Genki-S
Genki-S / map.cpp
Last active August 29, 2015 14:19
競プロで使えるC++プリントデバッグ(Operator Overloading)
#include <iostream>
#include <map>
using namespace std;
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
s << "{" << endl;
for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr) {
s << "\t" << (*itr).first << " : " << (*itr).second << endl;
}
s << "}" << endl;
require 'coverage'
Coverage.start
require './a_method.rb' # => true
a_method
p Coverage.result # => {"/Users/.../a_method.rb"=>[1, 1, 1, 10, nil, 1, nil]}
# Does not produce coverage because `Coverage.result` clears out the coverage
# p Coverage.result # coverage measurement is not enabled (RuntimeError)
def a_method
s = 0
10.times do |x|
s += x
end
s
end
(let ((physmem (car (split-string (shell-command-to-string "top -l 1 | head -n 10 | grep PhysMem") "\n")))
(mem-used nil)
(mem-unused nil))
(save-match-data (and (string-match "PhysMem: \\([0-9]+[MG]\\) used (\\([0-9]+[MG]\\) wired), \\([0-9]+[MG]\\) unused." physmem)
(setq mem-used (match-string 1 physmem)
mem-unused (match-string 3 physmem))))
# Show sushi if current second is 29
show_niku() {
local sec=$(date +%S)
if [ $sec -eq 29 ]; then
echo "🍣"
fi
}
# it goes well with zsh precmd hook
add-zsh-hook precmd show_niku
@Genki-S
Genki-S / fizzbuzz.sh
Last active August 29, 2015 14:11
fizzbuzz bash
number_to_fizzbuzz()
{
if [ $# -ne 1 ]; then
echo "Usage: $FUNCNAME NUMBER"
return 1
fi
local output=""
local number=$1
if [ $(($number % 3)) -eq 0 ]; then