Skip to content

Instantly share code, notes, and snippets.

@aont
aont / main.cpp
Created October 18, 2014 12:17
dispatch root command
#include <cstdio>
#include <cstring>
int main()
{
FILE* const sudo = popen("sudo -H -s", "r+");
fprintf(sudo, "echo login_test\n");
fflush(sudo);
@aont
aont / inspect.rb
Last active August 29, 2015 14:08
Mac Battery Capacity
#!/usr/bin/ruby
require 'nokogiri'
ioreg = IO::popen("ioreg -a -c AppleSmartBattery", "r")
doc = Nokogiri::XML(ioreg)
ioreg.close
cc=doc.xpath("//key[text()=\"CurrentCapacity\"]")[0]
@aont
aont / main.rb
Created November 8, 2014 08:10
loop
#!/usr/bin/ruby
require 'optparse'
Signal::trap("INT") do |signo|
exit
end
opt = OptionParser.new
@aont
aont / gnuplot.plt
Last active August 29, 2015 14:09
Gnuplot Memo
set log x
set key left top
# set term wxt
set format x "10^{%L}"
set term png enhanced size 1280,960 lw 2 fontscale 3
set term eps enhanced lw 1.5
@aont
aont / main.cpp
Created November 16, 2014 04:57
Bit Reverse
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <sys/time.h>
#include <algorithm>
#include <numeric>
double get_time_now()
{
@aont
aont / timer.sh
Last active August 29, 2015 14:10
timer
#!/bin/sh
TIME_BEGIN=$(date +%s)
TIME_NOW="$TIME_BEGIN"
TIME_END=$(date -d "$1" +%s)
TIME_LEFT=$(expr "$TIME_END" - "$TIME_NOW")
while [ ${TIME_LEFT} -gt 0 ]
do
echo ${TIME_LEFT}s left
@aont
aont / main.rb
Last active August 29, 2015 14:10
quasi streaming
#!/usr/bin/ruby
input="input"
$log=File::open("log.txt", "w")
def do_enc(input, start_at, stop_at, output)
command = "HandBrakeCLI -Z \"Android Tablet\" -e x264 -q 25.0 --x264-preset medium -E faac -i \"%s\" --main-feature -a 1 --subtitle-burned 1 -O -m --start-at duration:%s --stop-at duration:%s --decomb bob -o %s" % [input, start_at, stop_at, output]
$stderr.puts "----------------------------------"
$stderr.puts command
@aont
aont / main.rb
Created December 4, 2014 12:50
on-the-fly making gnuplot movie
#!/usr/bin/ruby
# coding: utf-8
require 'open3'
Open3.popen3('gnuplot') do |gp_in, gp_out, gp_err|
gp_in.puts "set term png"
gp_in.puts "set output \"| ffmpeg -y -f image2pipe -i - -vcodec copy out.mp4 >ffmpeg.log 2>&1"
500.times do |i|
@aont
aont / .emacs
Last active August 29, 2015 14:11
Emacs tramp settings
(require 'tramp)
(setq tramp-default-method "scp")
(setq tramp-ssh-controlmaster-options
(concat "-o ControlPath=" (getenv "HOME") "/.ssh/master-%%r@%%h:%%p")
)
(setq tramp-debug-buffer t)
(setq tramp-verbose 10)
@aont
aont / main.rb
Created December 18, 2014 12:07
analyze macports package list
#!/usr/bin/ruby
IO.popen("port -q installed", "r") do |port|
while line = port.gets
md_active = line.match(/\(active\)/)
is_active = md_active
if is_active