Skip to content

Instantly share code, notes, and snippets.

@nanki
nanki / tag.rb
Created April 2, 2015 23:32
tag EBS volumes
require 'aws-sdk-core'
require 'aws-sdk-resources'
require 'yaml'
config = YAML.load_file('config.yml')[:tag]
Aws.config.update(
region: 'ap-northeast-1',
credentials: Aws::Credentials.new(config[:access_key_id], config[:secret_access_key])
)
@nanki
nanki / ble.rb
Last active December 10, 2016 14:21
framework 'IOBluetooth'
class A
def initialize
@c = CBCentralManager.alloc.initWithDelegate(self, queue:nil)
end
def centralManagerDidUpdateState(central)
if central.state == CBCentralManagerStatePoweredOn
@c.scanForPeripheralsWithServices(nil, options:nil)
import IOBluetooth
class A: NSObject, CBCentralManagerDelegate {
var c: CBCentralManager!
init() {
super.init()
c = CBCentralManager(delegate:self, queue:nil)
}
@nanki
nanki / hem
Created April 29, 2014 02:01
heavy exclamation mark
❗️❗️❗️❗️❗️❗️
@nanki
nanki / fluentd.conf
Last active August 29, 2015 13:56
fluentd-tracer
<match fluent.digraph fluent.warn>
type websocket
port 8080
</match>
...
request = require 'request'
http = require 'http'
url = require 'url'
cp = require 'child_process'
command = (command, args, callback) ->
cmd = cp.spawn command, args
if callback
result = new Buffer(0)
@nanki
nanki / json2plist
Last active December 19, 2015 14:49
convert JSON to Property List.
#!/usr/bin/env ruby
# -*- coding: UTF-8 -*-;
require 'base64'
require 'pathname'
require 'english'
require 'json'
require 'CFPropertyList'
@nanki
nanki / fluent-dump.coffee
Last active December 19, 2015 12:59
dump fluentd forward protocol.
# $ coffee fluent-dump.coffee [bind] [port]
net = require 'net'
dns = require 'dns'
util = require 'util'
dgram = require 'dgram'
msgpack = require 'msgpack'
msgpack.raw = require 'msgpack-raw'
@nanki
nanki / grayscale.py
Last active December 16, 2015 04:39
display an image with xterm-256/unicode braille patterns.
import sys
import math
from random import random
from PIL import Image, ImageOps, ImageEnhance
def dot(bits):
bits = bits & 7 | (bits & 112) >> 1 | (bits & 8) << 3 | bits & 128
return unichr(0x2800 + bits)
class Grayscale24:
@nanki
nanki / mandelbrot.py
Created April 13, 2013 14:58
render mandelbrot set on terminal
import sys
import math
def dot(bits):
bits = bits & 7 | (bits & 112) >> 1 | (bits & 8) << 3 | bits & 128
return unichr(0x2800 + bits)
def mandelbrot(x, y, r, iteration=1000):
xx = 1.4 * float(x - 1.4 * r) / r
yy = 1.4 * float(y - r) / r