Skip to content

Instantly share code, notes, and snippets.

@NeoCat
NeoCat / switch-tty.sh
Last active Mar 28, 2018
Script to switch console attached to a command (for Linux)
View switch-tty.sh
#!/bin/bash
# For example: switch-tty.sh `pidof vi` `tty`
target=$1
dest=$2
if [ -z "$target" -o -z "$dest" ]; then
echo "usage: $0 pid target"
exit 1
fi
@NeoCat
NeoCat / monitor_ios_battery.rb
Last active Dec 31, 2016
Monitor iOS battery level and stop charging when the level >= 80% (restart when the level < 80%)
View monitor_ios_battery.rb
#!/usr/bin/ruby
require 'timeout'
THRESH = 80 # %
SPEED = 60 # sec / %
$IDEVICEINFO_CMD = '/usr/local/bin/ideviceinfo'
$POWER_ON_CMD = 'curl -s -m 5 192.168.x.x/on'
$POWER_OFF_CMD = 'curl -s -m 5 192.168.x.x/off'
$state = nil
$caffe_pid = nil
@NeoCat
NeoCat / 0001-Adds-NAPT-and-port-mapping-functionality-to-esp8266-.patch
Last active Mar 8, 2019
Patch to add NAPT and port mapping functionality to esp8266
View 0001-Adds-NAPT-and-port-mapping-functionality-to-esp8266-.patch
From 1dfbeab6f4ca7287e27c31a9f90ddec3343a18d5 Mon Sep 17 00:00:00 2001
From: NeoCat <neocat@neocat.jp>
Date: Thu, 13 Oct 2016 22:19:22 +0900
Subject: [PATCH] Adds NAPT and port mapping functionality to esp8266 lwip
esp8266 can handle 2 network interfaces (Wifi client and softAP)
simultaneously in the WIFI_AP_STA mode.
Currently IP_FORWARD is implemented in lwip to forward packets
between 2 interfaces, but static routing must be setup manually.
This patch adds IP_NAPT config option to enable esp8266 to use
@NeoCat
NeoCat / config.py
Created Sep 23, 2016
keyhacを使ってNICOLA配列(ローマ字入力設定用)にするためのconfig例
View config.py
import sys
import os
import datetime
import subprocess
import re
import time
from keyhac import *
class NICOLA:
@NeoCat
NeoCat / power.html
Last active May 16, 2018
スマートメーターからの電力をBP35A1を使って取得・Webブラウザ上でリアルタイムにグラフ描画 (詳細: http://d.hatena.ne.jp/NeoCat/20160117/1453021993 )
View power.html
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Power</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.2.0.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<style type="text/css">
@NeoCat
NeoCat / SmartMeter.ino
Last active May 26, 2020
スマートメーターから瞬時電力を取得して7セグに表示するArduino用スケッチ
View SmartMeter.ino
#include <SoftwareSerial.h>
// Detail: http://d.hatena.ne.jp/NeoCat/20160110/1452407542
//-----------------------------------------------------------
// Configurations
//-----------------------------------------------------------
// B-route ID and Password (PANA authentication)
#define ID "0000XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
@NeoCat
NeoCat / test-pib-iser.sh
Created Apr 1, 2015
Test tgtd iSER connection via pib (tested in Fedora 21)
View test-pib-iser.sh
#!/bin/sh
IB_ADDR=172.24.100.1
TARGET_IQN=iqn.2015-05.com.example:test
if [ $EUID -ne 0 ]; then
sudo "$0" "$@"
exit $?
fi
@NeoCat
NeoCat / gist:a6189f245347581d608c
Created Jan 20, 2015
twicli CSS - Don't enlarge thumbnails on hover & enlarge thumbnails when selected
View gist:a6189f245347581d608c
/* twicliの設定→ユーザスタイルシートに下記をペーストして保存 */
/* サムネールをマウスオーバーで拡大しない */
.thumbnail-image:hover { max-width: 32px; width: 32px\9; }
/* tweetをクリックで選択した時にサムネールを拡大 */
div.selected img.thumbnail-image { width: auto; max-width: 300px; }
@NeoCat
NeoCat / tweet-ingress-damage.rb
Last active Aug 29, 2015
Monitor your GMail mail box and tweet the damage report.
View tweet-ingress-damage.rb
#!/usr/bin/ruby
require 'net/imap'
require 'nokogiri'
require 'twitter'
require 'cgi'
require 'open-uri'
mail_user = '***@gmail.com'
mail_password = '***'
mail_label = 'Ingress'
@NeoCat
NeoCat / add2numbers_12lang_polyglot
Created Apr 21, 2014
12 language polyglot which adds 2 numbers from stdin. Runnable in Bash/Brainf**k/C/CLIPS/INTERCAL/Perl/Perl 6/Python/Ruby/Pike/Prolog (swi)/Whitespace, tested in Ideone.com http://ideone.com/JmXx4l .
View add2numbers_12lang_polyglot
#define x /* ++[>[-]+>>++++++++++[>++++++[>++++++<-]>++<<<<[[-]>+>>>>,----------<<<<<]>[<+>-]>>>>[>+>+<<-]<[>>-<<-]>>>>+<[[-]>-<]>[[-]<<[+]<<<<<<[-]>>[-]+<<>>>>>>>>]>>>>>>>>>>[>+<-]<[>+<-]<[>+<-]<[>+<-]<[>+<-]<[>+<-]<[>+<-]<[>+<-]<[>+<-]<<<<[>>>>+<<<<-]<<<<-]<<<[>>+>+<<<-]>>[<<+>>-]>-[[-]>>>>>>>+++++++++[>>>>>>>>>>>>>>>>>>>>[>+<-]<[>+<-]<[>+<-]<[>+<-]<[>+<-]<[>+<-]<[>+<-]<[>+<-]<[>+<-]<[>+<-]<[>+<-]<[>+<-]<[>+<-]<[>+<-]<[>+<-]<[>+<-]<[>+<-]<[>+<-]<[>+<-]<<-]<<<<<<<]<<<-]>>>>>>>>>>>>>>>>>>>>[>>>>>>>>>+<<<<<<<<<-]<[>>>>>>>>>+<<<<<<<<<-]<[>>>>>>>>>+<<<<<<<<<-]<[>>>>>>>>>+<<<<<<<<<-]<[>>>>>>>>>+<<<<<<<<<-]<[>>>>>>>>>+<<<<<<<<<-]<[>>>>>>>>>+<<<<<<<<<-]<[>>>>>>>>>+<<<<<<<<<-]<[>>>>>>>>>+<<<<<<<<<-]<++++++++[>>>>>>>>>>[<<<<<<<<+<+>>>>>>>>>-]<<<<<<<<[>>>>>>>>+<<<<<<<<-]+++++++++[<[[<<+>>-]<<->>]<<[>>+<<-]>>>-]<[[-]>>>>>>>>>---------->+<<<<<<<<<<][<+>-]>[<+>-]>[<+>-]>[<+>-]>[<+>-]>[<+>-]>[<+>-]>[<+>-]>[<+>-]>[<+>-]>[<+>-]>[<+>-]>[<+>-]>[<+>-]>[<+>-]>[<+>-]>[<+>-]>[<+>-]><<<<<<<<<<<<<<<<<<<-]>>>>>>>>>>>>+++++++++[<<[[-