Skip to content

Instantly share code, notes, and snippets.

View hiroakis's full-sized avatar

Hiroaki Sano hiroakis

View GitHub Profile
@hiroakis
hiroakis / installation_pyenv
Last active December 15, 2015 04:49
My Python developing environment.
# Install pyenv in ~/.pyenv
cd ~
git clone git://github.com/yyuu/pyenv.git .pyenv
echo 'export PYENV_ROOT="${HOME}/.pyenv"' >> ~/.zshrc
echo 'if [ -d "${PYENV_ROOT}" ]; then' >> ~/.zshrc
echo ' export PATH=${PYENV_ROOT}/bin:$PATH' >> ~/.zshrc
echo ' eval "$(pyenv init -)"' >> ~/.zshrc
echo 'fi' >> ~/.zshrc
@hiroakis
hiroakis / 01_riak.spec
Last active December 15, 2015 14:09
Custom Riak RPMs spec file.
%define _version 1.3.0
%define _revision 1.3.0
%define _release 1
Name: riak
Version: %{_version}
Release: %{_release}%{?dist}
License: Apache License
Group: Development/Libraries
Source: %{name}-%{_revision}.tar.gz
@hiroakis
hiroakis / functools_partial_example.py
Created July 13, 2013 18:21
functools.partial example
import functools
def calc(x, y, mode):
if mode == '+':
return x + y
elif mode == '-':
return x - y
elif mode == '*':
return x * y
elif mode == '/':
@hiroakis
hiroakis / functools_wraps_example.py
Created July 13, 2013 18:24
Create my own decorator using functools.wraps.
import functools
def ore(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
print "@ore : oreoreoreoreore"
return func(*args, **kwargs)
return wrapper
def plus(x, y):
@hiroakis
hiroakis / bigip_operation.py
Last active December 30, 2015 08:39
This is an example that operate BIG IP via Python using pycontrol.
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import pycontrol.pycontrol as pc
import os
host = 'xxx.xxx.xxx.xxx'
user = 'xxxxxx'
password = 'xxxxxx'
@hiroakis
hiroakis / IAM
Created January 22, 2016 12:17
IAM
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"NotAction": "iam:*",
"Resource": "*"
},
{
"Effect": "Allow",
@hiroakis
hiroakis / Rakefile_serverspec
Last active June 5, 2016 21:27
serverspec for my environment
require 'rake'
require 'rspec/core/rake_task'
require 'yaml'
require 'highline/import'
properties = YAML.load_file('properties.yaml')
ENV['SSH_USER'] = ask("Enter ssh user: ") { |q| q.echo = true }
ENV['SSH_PASSWORD'] = ask("Enter ssh password: ") { |q| q.echo = false }
@hiroakis
hiroakis / spec_helper.rb.patch
Last active October 14, 2016 05:46
A patch for spec_helper.rb in serverspec. This patch enables "rake spec" command to require server login password.
--- spec_helper.rb.org 2013-11-04 19:21:50.000000000 +0900
+++ spec_helper.rb 2013-11-04 23:01:26.000000000 +0900
@@ -6,12 +6,9 @@
include Serverspec::Helper::DetectOS
RSpec.configure do |c|
- if ENV['ASK_SUDO_PASSWORD']
- require 'highline/import'
- c.sudo_password = ask("Enter sudo password: ") { |q| q.echo = false }
- else
@hiroakis
hiroakis / tail.go
Created January 15, 2017 17:14
The tail command implementation written in go. The command support -F option. It is default action.
package main
import (
"flag"
"fmt"
"io"
"os"
"time"
"github.com/fsnotify/fsnotify"
@hiroakis
hiroakis / enqueue.rb
Last active March 27, 2017 20:50
queue implementation using MySQL
require 'mysql2-cs-bind'
def get_db
return Mysql2::Client.new(
:host => 'localhost',
:port => 3306,
:username => 'root',
:password => '',
:database => 'queue_test',
:reconnect => true,