Skip to content

Instantly share code, notes, and snippets.

View yyamasak's full-sized avatar

Yusuke Yamasaki yyamasak

View GitHub Profile
@yyamasak
yyamasak / rewrite_vs_version_info.tcl
Last active December 19, 2015 02:28
This script replaces FileVersion in VS_VERSION_INFO block. I wrote it to use with TclApp because TclApp replaces StringFileInfo block only. limitations: For Windows only. It leaves ProductVersion as is to see what version of basekit is used. usage: tclsh rewrite_vs_version_info.tcl executable FileVersion(x.x.x.x)
proc stringfy_version {bin} {
binary scan $bin s4 v
foreach {fv2 fv1 fv4 fv3} $v break
set fv "$fv1.$fv2.$fv3.$fv4"
return $fv
}
proc binary_version {v} {
foreach {fv1 fv2 fv3 fv4} [split $v .] break
binary format s4 [list $fv2 $fv1 $fv4 $fv3]
@yyamasak
yyamasak / array_dict_comparison.tcl
Created April 4, 2014 00:57
Passing dict by value is 10 times faster than passing array by ref
set d [dict create]
set str1 "abcdefghijklmnopqrstuvwxyz"
for {set i 0} {$i < 10000} {incr i} {
set str2 [format "${str1}%4d" $i]
set ary($i) $str2
dict set d $i $str2
}
proc test1 {_ary} {
@yyamasak
yyamasak / kbs-memo.md
Last active August 29, 2015 14:07
Kitgen Build System メモ

2014-10-16現在、kbs.tclはtcl8.5.16, tcl8.6.2に対応していない。

あとパッケージ類も、最新のバージョンではなかったりする。

fossilで配布しているソースコードは、anonymousユーザーで、ワンタイムパスワード認証しないといけない。

今のところkbs.tclでは自動的にダウンロードができない(fossil.exeを使えばよいのだが。) 一時的な回避策として、ローカルウェブサーバを立ててダウンロードさせる必要があった。

本題ではないが、おすすめのお手軽ウェブサーバはこれ。

@yyamasak
yyamasak / kbs.tcl
Created January 13, 2015 15:30
kbs.tcl 0.4.6-1
#! /bin/sh
##
# @file kbs.tcl
# Kitgen Build System
# @mainpage
# @synopsis{kbs.tcl ?-option? .. ?command? ..}
#
# For available options and commands see help() or type './kbs.tcl help'.
# Online documentation can be found at http://wiki.tcl.tk/18146
#
@yyamasak
yyamasak / TestGetPrivateProfileSectionNames.cs
Created March 17, 2015 11:17
GetPrivateProfileSectionNames.exe .\system.ini
using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.IO;
namespace TestGetPrivateProfileSectionNames
{
public class Program
{
[DllImport("kernel32.dll")]
proc read_inifile_section_names {f} {
set sections {}
set ch [open $f r]
while {[gets $ch line] != -1} {
if {[regexp {^\[(.+)\]$} $line -> section]} {
lappend sections $section
}
}
close $ch
return $sections
@yyamasak
yyamasak / reformat.tcl
Created April 19, 2015 06:27
The original code was taken from: Reformat Tcl code indentatioin http://wiki.tcl.tk/15731
proc reformat {tclcode {pad 4}} {
set lines [split $tclcode \n]
set out ""
set continued no
set oddquotes 0
set line [lindex $lines 0]
set indent [expr {([string length $line]-[string length [string trimleft $line \ \t]])/$pad}]
set pad [string repeat " " $pad]
foreach orig $lines {
@yyamasak
yyamasak / 0_reuse_code.js
Last active August 29, 2015 14:22
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
def accum(n, x, y)
t,s=STDIN.gets.split.map(&:to_i)
case t
when 1
x+=s
when 2
y+=s
when 3
sum=x+y
x=x-s*x/sum
@yyamasak
yyamasak / backtrace.tcl
Last active December 15, 2015 09:06
Returns the backtrace of the call stack as a list
proc backtrace {} {
set frames [list]
for {set i 1} {$i < [info level]} {incr i} {
lappend frames [dict get [info frame $i] cmd]
}
return $frames
}