Skip to content

Instantly share code, notes, and snippets.

View kbinani's full-sized avatar

kbinani kbinani

View GitHub Profile
@kbinani
kbinani / build_gcc_rpm_package.sh
Last active August 29, 2015 14:18
build_gcc_rpm_package.sh
# git clone https://github.com/ngyuki/checkinstall.git
# cd checkinstall
# make
# sudo make install
# GCC_VERSION=4.9.2
# wget http://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.gz || { echo "Failed downloading tarball" && exit 1; }
# tar zxf gcc-$GCC_VERSION.tar.gz
# cd gcc-$GCC_VERSION
@kbinani
kbinani / autoincense.haka.yamashi.ro.cron
Last active August 29, 2015 14:16
autoincense.haka.yamashi.ro.cron
0 0 * * * API_TOKEN="xxxx"; HOUR_FROM=11; HOUR_TO=22; function get_rand { local FROM=$1; local TO=$2; local DIFF=$(echo "$TO - $FROM" | bc); echo "$FROM + $DIFF * $(echo "ibase=16; $(openssl rand -hex 2 | tr a-f A-F)" | bc) / 65535" | bc; }; echo "sleep $(get_rand 0 59) >/dev/null 2>&1; curl -d token=$API_TOKEN http://haka.yamashi.ro/api/v1/incenses >/dev/null 2>&1" | at $(printf "\%02d:\%02d" $(get_rand $HOUR_FROM $HOUR_TO) $(get_rand 0 59)) >/dev/null 2>&1
@kbinani
kbinani / create_iso_image_from_directory.sh
Last active August 29, 2015 14:13
Create ISO disk image from existing directory
mkdir hoge
touch hoge/hoge.txt
hdiutil makehybrid -udf -o hoge.iso hoge
@kbinani
kbinani / file_get_contents.cpp
Created December 1, 2014 02:58
PHP's file_get_contents function in C++
#include <fstream>
inline std::string file_get_contents(std::string const& path)
{
return (std::stringstream() << std::ifstream(path).rdbuf()).str();
}
@kbinani
kbinani / backtrace.cpp
Created June 23, 2014 07:22
print backtrace at runtime
// #include <execinfo.h>
void * trace[128];
int const num_trace = backtrace(trace, 128);
char ** trace_symbols = backtrace_symbols(trace, num_trace);
for (int i = 0; i < num_trace; ++i) {
std::cout << trace_symbols[i] << std::endl;
}
free(trace_symbols);
@kbinani
kbinani / gist:9598667
Last active August 29, 2015 13:57
How to install node.js package on Windows, VisualStudio 2012, with multiple versions of python installed
npm install -g ffi --python=C:\Python27\python.exe --msvs_version=2012
#import <Cocoa/Cocoa.h>
#include <wx/wx.h>
#include <wx/caret.h>
#include <wx/glcanvas.h>
#include <wx/rawbmp.h>
#include <sstream>
#include <boost/chrono.hpp>
#include <boost/optional.hpp>
#include <vector>
@kbinani
kbinani / fetch_stacktrace_symbols.rb
Created October 17, 2013 02:22
Get actual symbol names from a stack trace generated by`strip(1)`ped binary.
#!/usr/bin/env ruby
require 'optparse'
def create_symbol_list(binary_path, arch)
temp = `mktemp -t tmp`
`nm -arch #{arch} "#{binary_path}" 2>/dev/null \
| awk '$3 != "" { print $0 }' \
| sort \
> "#{temp}"`
@kbinani
kbinani / get_package_id.sh
Created July 24, 2013 14:29
Get package id from a *.pkg file (Mac OSX).
#!/bin/bash
function get_package_id { (
readonly PKG_INFO=PackageInfo
local PKG=$(cd "$(dirname "$1")"; pwd)/$(basename "$1")
local EXCLUDES=
for FILE in $(xar -t -f "$PKG" | grep -v $PKG_INFO); do
EXCLUDES="$EXCLUDES --exclude $FILE"
done
local TEMP=$(mktemp -t hoge | tr -d '\r')
function get_cursor_hotspot_x { (
local FILE_PATH=$1
od -N 2 -j 10 -t u "$FILE_PATH" | awk '{print $2}' | head -1
) }
function get_cursor_hotspot_y { (
local FILE_PATH=$1
od -N 2 -j 12 -t u "$FILE_PATH" | awk '{print $2}' | head -1
) }