Skip to content

Instantly share code, notes, and snippets.

@yfuruyama
yfuruyama / gist:5508977
Last active December 16, 2015 22:39
gdb utility
# print 'next' field of object(by chain)
#
# usage:
# (gdb)pnext ptr (equals to 'print ptr->next')
# (gdb)ENTER (equals to 'ptr->next->next')
define pnext
init-if-undefined $a = $arg0
init-if-undefined $b = $arg0
# 0 means initialize
@yfuruyama
yfuruyama / gist:5743666
Created June 9, 2013 14:05
show git branch at bash prompt
showbranch='git br 2>&1 | ruby -ne "if /\* (.*)/ =~ \$_.chomp; print \$1; end"'
export PS1='$('"${showbranch}"')'
@yfuruyama
yfuruyama / yield
Created June 30, 2013 02:27
yield
function xhr(callback) {
console.log('now requesting...');
setTimeout(function () {
var response = {
status: '200'
};
callback(response);
}, 1000);
}
@yfuruyama
yfuruyama / gist:6660263
Created September 22, 2013 14:12
plack handler
package Ult::Server;
use strict;
use warnings;
use IO::Socket::INET;
use Plack::Util;
use Plack::HTTPParser qw( parse_http_request );
use constant MAX_REQUEST_SIZE => 131072;
sub new {
@yfuruyama
yfuruyama / saynumber.sh
Created October 18, 2013 03:37
Practice for number in English
#!/bin/bash
interval_sec=1
say_rate=240 # words/minute
while :
do
number=$RANDOM # RANDOM is between 0 and 32767 in bash
say -r ${say_rate} ${number}
sleep ${interval_sec}
pbpaste | perl -pne 's/
/\n/g' | perl -pne 's/\t/ | /g; s/(.*)/| $1 |/' | pbcopy
@yfuruyama
yfuruyama / lsview.py
Last active December 29, 2015 12:19
[lldb]show UIView recursively
# -*- coding: utf-8 -*-
import re
import lldb
def lsview(debugger, command, result, internal_dict):
root_view = _get_root_view()
view_hierarchy = get_view_hierarchy(root_view)
print_view_hierarchy(view_hierarchy)
@yfuruyama
yfuruyama / gist:8155699
Created December 28, 2013 03:08
Applescript for enabling bluetooth
tell application "System Preferences"
activate
set the current pane to pane "Bluetooth"
end tell
tell application "System Events"
tell process "System Preferences"
click (menu button of splitter group of group of window 1)
click ((menu item "Update Services") of menu of menu button of splitter group of group of window 1)
end tell
end tell
@yfuruyama
yfuruyama / gist:8337265
Created January 9, 2014 16:35
shuuron makefile
PAPER=shuuron
OUTPUT_DIR=out
# TeX commands
TEX=platex
TEX_OPTIONS=-kanji=utf8 -output-directory=$(OUTPUT_DIR)
DVI2PDF=dvipdfmx
DVI2PDF_OPTIONS=-o $(OUTPUT_DIR)/$(PAPER).pdf
BIBTEX=pbibtex
@yfuruyama
yfuruyama / float2fix.c
Last active October 11, 2024 08:58
convert floating point number to fixed point number
#include <stdio.h>
#include <math.h>
#define FIXED_BIT 12
unsigned short int float2fix(float n)
{
unsigned short int int_part = 0, frac_part = 0;
int i;
float t;