Skip to content

Instantly share code, notes, and snippets.

@kei-p
kei-p / objc-regex
Last active August 29, 2015 14:16
Objective-C regex
NSString* pattern = @"^(\\d{3})$";
NSError* error = nil;
NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:pattern options:NSRegularExpressionCaseInsensitive error:&error];
NSString* text = @"122";
NSArray *matches = [regex matchesInString:text options:0 range:NSMakeRange(0, text.length)];
if(matches.count>0){
NSLog(@"%@",matches);
}else{
@kei-p
kei-p / gist:e7cce87aaf404caef3d4
Last active October 13, 2015 00:48
fetch_ec2_instance_name
## get instance_id
instance_id=$(curl http://169.254.169.254/latest/meta-data/instance-id)
## get Name Tag
instance_name=$(aws ec2 describe-instances --instance-ids ${instance_id} \
--query 'Reservations[*].Instances[*].Tags[?Key==`Name`].Value' \
--output text)
echo $instance_name
[core]
editor = vim -c \"set fenc=utf-8\"
[alias]
ctree = log --color --graph --date-order --pretty=format:'%x09%C(yellow)%h%Creset%x09%C(red)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
tree = log --color --graph --date-order --all --pretty=format:'%x09%C(yellow)%h%Creset%x09%C(red)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
ck = checkout
pff = pull --ff-only
prebase = pull --rebase
fprune = fetch --prune
prbdev = pull --rebase origin develop
@kei-p
kei-p / download.html
Last active March 3, 2016 05:15
GAS spreadsheet to json
<style type="text/css">
#json {
height: 320px;
overflow: scroll;
border:1px solid #ddd;
padding:10px;
}
</style>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Blue Component</key>
<real>0.48771023750305176</real>
<key>Green Component</key>
<real>0.48781105875968933</real>
@kei-p
kei-p / json_parse.ry.rb
Created March 28, 2016 08:52
Racc Samples
class JsonParser
options no_result_var
rule
json_text : ws object ws
{ val[1] }
| ws array ws
{ val[1] }
ws :
| ws SPACE
@kei-p
kei-p / dummy_response.rb
Last active April 11, 2016 05:53
DummyResponse with Faraday
require 'bundler/setup'
Bundler.require
module Faraday
class Dummy < Faraday::Middleware
def call(env)
if Random.new.rand(0..1) == 0
@app.call(env).on_complete do |env|
env
end
@kei-p
kei-p / code2index.rb
Last active April 11, 2016 10:43
CSV cordinate to index
require 'pry'
CODES = ('A'..'Z')
CODES_SIZE = CODES.to_a.size
def index2code(n)
num = n
chars = []
codes = CODES.to_a
begin
@kei-p
kei-p / navbar.html
Created April 20, 2016 01:32
non-responsibe-navbar
<nav class='navbar navbar-default navbar-static-top'>
<div class='container-fluid'>
<a href='#' class='navbar-brand'>Demo</a>
<ul class="nav navbar-right pull-right" id='header-buttons'>
<li class='navbar-btn'>
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">
<span class="glyphicon glyphicon-plus" aria-hidden='true'></span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
@kei-p
kei-p / fetch_google_spreadsheet.rb
Last active April 20, 2016 09:10
Fetch google spreadsheet
require 'bundler/setup'
require 'google_drive'
require 'json'
sheet_id = ENV['SHEET_ID']
json_file = ENV['AUTH_JSON']
options = JSON.parse(File.read(json_file))
key = OpenSSL::PKey::RSA.new(options['private_key'])