It's only fair to share...Tweet about this on TwitterShare on Google+Share on FacebookShare on TumblrEmail this to someone

The source is now being hosted at both GitHub and my personal TsundereGit.
https://github.com/Frederick888/php-bencode
https://git.tsundere.moe/Frederick888/php-bencode

From Wikipedia
Bencode is the encoding used by the peer-to-peer file sharing system BitTorrent for storing and transmitting loosely structured data.

Apart from the “torrent” files, it is also used to store local data in some BitTorrent clients instead of other lightweight databases such as SQLite. However, if one gets hundreds of torrents, decoding the file would be extremely slow by some pure PHP libraries. This is why I decided to implement a PHP extension to boost the process.

There is an existed extension on Google Code, which you can also find an exportation to GitHub with some patches. But it seems that it can only parse a Bencode into plain array or convert an array back which may cause data loss during the conversion, e.g. empty arrays or lists.

Bencode should be handled by objects. But I can hardly find any introductions about handling objects in a PHP extension (reading the header file may be a better choice but it may cost a little long). Then I found PHP-CPP, which is quite friendly to new PHP extension developers. It’s a pity that it cannot be packed as a PECL package but it would be easy to build a binary package instead.

The development is not finished yet and I’m considering adding more useful features. Also, there may be lots of redundant codes to clean up 😉

It's only fair to share...Tweet about this on TwitterShare on Google+Share on FacebookShare on TumblrEmail this to someone

“vcgencmd” is a useful command on Raspberry Pi provided by Raspbian.

By taking advantage of this command, users can easily get the temperature of Pi, check the frequency of CPU and etc. There’re many options for this command but it lacks a bash completion script. So I wrote one based on the document by elinux.

Here it is. Place it under /etc/bash_completion.d/. (Download: vcgencmd-complete.zip)

_vcgencmd () {
    local cur prev commands opts_clock opts_volts opts_codec opts_config opts_mem opts_display
    commands=$(vcgencmd commands)
    commands=${commands:10:${#commands}-11}
    commands="${commands//,} commands"
    opts_clock="arm core h264 isp v3d uart pwm emmc pixel vec hdmi dpi "
    opts_clock="45  1    28   42  43  22   25  47   29    10  9    4 ""$opts_clock"
    opts_volts="core sdram_c sdram_i sdram_p"
    opts_codec="H264 MPG2 WVC1 MJPG WMV9"
    opts_config="int str
        arm_freq
        config_hdmi_boost
        core_freq
        disable_commandline_tags
        disable_l2cache
        emmc_pll_core
        force_eeprom_read
        force_pwm_open
        framebuffer_ignore_alpha
        framebuffer_swap
        hdmi_force_cec_address
        over_voltage
        over_voltage_avs
        overscan_bottom
        overscan_left
        overscan_right
        overscan_top
        pause_burst_frames
        program_serial_random
        sdram_freq
        temp_limit"
    opts_mem="arm gpu"
    opts_display="0 1"

    COMPREPLY=()
    cur=$(_get_cword)
    prev=${COMP_WORDS[COMP_CWORD-1]}

    case "$prev" in
        "vcgencmd")
            COMPREPLY=($(compgen -W "$commands" "$cur"))
            ;;
        "measure_clock")
            COMPREPLY=($(compgen -W "$opts_clock" "$cur"))
            ;;
        "measure_volts")
            COMPREPLY=($(compgen -W "$opts_volts" "$cur"))
            ;;
        "codec_enabled")
            COMPREPLY=($(compgen -W "$opts_codec" "$cur"))
            ;;
        "get_config")
            COMPREPLY=($(compgen -W "$opts_config" "$cur"))
            ;;
        "get_mem")
            COMPREPLY=($(compgen -W "$opts_mem" "$cur"))
            ;;
        "display_power")
            COMPREPLY=($(compgen -W "$opts_display" "$cur"))
            ;;
    esac

    return 0
}
complete -F _vcgencmd vcgencmd

It's only fair to share...Tweet about this on TwitterShare on Google+Share on FacebookShare on TumblrEmail this to someone

この2つのタイトルの発売日は元々近かったので、予約した時に同一な注文にした。それで、ただ延ばされただけならそれほど不幸なことじゃないけど、延ばされたあとこれらの発売日は随分離れちゃった(「よるのないくに」は10月1日、「ソフィーのアトリエ」は11月19日)。それにガストショップのルールによって、同一注文の品の配達も一緒にする。というわけでこのままだと「よるのないくに」も11月まで待たなければいけない。

gust_shop_extension

大変だと思ってサポートに連絡したら、スタッフの方から注文を2つにすることもできなかった。仕様がなかったから、一度注文をキャンセルさせ、その後こっちから再注文するわけになってきた。

今年この2つのタイトルをやれるかな・・・(遠い目)

It's only fair to share...Tweet about this on TwitterShare on Google+Share on FacebookShare on TumblrEmail this to someone

The combination of touchscreen and NFC module is quite useful for many situations. For example, you may build a simple signup system or an advanced billing system which is a little more complex.

Here we’ll use Waveshare 3.5″ Touchscreen and ITEAD PN532 NFC Module. Both the prices of the two components are pretty fare and they can basically meet most of our requirements.

The Waveshare touchscreen comes with a DVK512 chip which doesn’t support SPI master-slave architecture. This means we cannot use the PN532 with SPI at the same time. Fortunately, ITEAD PN532 provides various interfaces including SPI, I2C and UART. I’ll show you how to make PN532 over I2C work with Waveshare touchscreen together.

続きを読む

It's only fair to share...Tweet about this on TwitterShare on Google+Share on FacebookShare on TumblrEmail this to someone

Different from Windows 7, there isn’t an efficient way to manage Network Locations in Windows 8.1.
This problem can sometimes be quite annoying. For example, there may be an increasing number after your network name such as “My Network 2”, “My Network 3″… However you usually won’t use the legacy profiles once again so the storage of the configurations just becomes redundant.

I finally found the solution at Microsoft Technet, it’s quite easy and I’ll just do a memo here.

1. Run Registry Editor. (press Windows button + R, type regedit, click OK)
2. Go to this folder: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles.

The Profiles folder will eventually give you all the network locations (past or recent) that you have used. Each network location is represented by a subfolder.

If you want to set up again the network locations when the network adapter connects to the network, delete all the subfolders of Profiles folder.

If you want to rename the network location, click on the right subfolder and edit the key named ProfileName and input the name you desire for the network location.

Thank Shiva Sharma for sharing.

It's only fair to share...Tweet about this on TwitterShare on Google+Share on FacebookShare on TumblrEmail this to someone

phpMyAdminがSourceForgeから撤退した以上、今新しいphpMyAdminの更新スクリプトは必要になる。
この前にもごく簡単なスクリプトを利用してアップデートしたけど、今phpMyAdmin自身のサイトはhttp://xxxx/latest/downloadという固定型の更新リンクを対応してないから、今回の新しい方はアップデートチェックやバージョンの比較も対応しなきゃいけない。
さて、閑話休題、早速新しいスクリプトを紹介しよう。

.
├── current
├── latest
└── update_phpmyadmin.sh

初めての利用する前にはcurrentというファイルに今phpMyAdminのバージョンを書き込まなきゃ、じゃないとこのスクリプトは正常にバージョンの比較できなくなる。

user@host:~/scripts/phpmyadmin$ cat current
4.4.11

$PHPMYADMIN_HOMEと$VERSION_CHKこの2つの変数を変更することを忘れずにね

#!/bin/bash
SCRIPT_HOME=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
PHPMYADMIN_HOME="/var/www/phpmyadmin"
TIMESTAMP=`date "+%s%N"`
VERSION_CHK="https://domain.com/phpmyadmin/version_check.php?&_nocache=""$TIMESTAMP"

vercomp () {
    if [[ $1 == $2 ]]
    then
        return 0
    fi
    local IFS=.
    local i ver1=($1) ver2=($2)
    # fill empty fields in ver1 with zeros
    for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
    do
        ver1[i]=0
    done
    for ((i=0; i<${#ver1[@]}; i++))
    do
        if [[ -z ${ver2[i]} ]]
        then
            # fill empty fields in ver2 with zeros
            ver2[i]=0
        fi
        if ((10#${ver1[i]} > 10#${ver2[i]}))
        then
            return 1
        fi
        if ((10#${ver1[i]} < 10#${ver2[i]}))
        then
            return 2
        fi
    done
    return 0
}

if [[ `whoami` != "root" ]]; then
    echo "Please run as root"
    exit 1
fi

cd $SCRIPT_HOME
curl "$VERSION_CHK" 2>/dev/null | sed -r "s/.*version\":\"([0-9\\.]*)\".*/\\1/" > latest
CURRENT=`cat current`
LATEST=`cat latest`
echo "The current version is: $CURRENT"
echo "The latest  version is: $LATEST"
vercomp $CURRENT $LATEST
case $? in
    0) echo "No updates"; exit 0;;
    1) echo "You are ahead of the latest one?!"; exit 1;;
    2) echo "Updating to $LATEST from $CURRENT, are your sure? [y/n]";;
esac
read CONTINUE
if [[ $CONTINUE != "y" ]]; then
    exit 0
fi

wget --content-disposition "https://files.phpmyadmin.net/phpMyAdmin/$LATEST/phpMyAdmin-$LATEST-all-languages.tar.xz"
TAR_FILE=`find $SCRIPT_HOME -name "phpMyAdmin-*.tar.xz" -print`
if [[ -z $TAR_FILE ]]; then
    echo "Download failed"
else
    echo "$TAR_FILE is successfully download"
    tar Jxvf $TAR_FILE
    TAR_DIRECTORY=`find $SCRIPT_HOME -name "phpMyAdmin-*" -type d -print`
    cp "$PHPMYADMIN_HOME/config.inc.php" "$TAR_DIRECTORY/"
    rm -rf "$PHPMYADMIN_HOME"
    mv "$TAR_DIRECTORY" "$PHPMYADMIN_HOME"
    #do a chown if you need
    #chown user:group "$PHPMYADMIN_HOME" -R
    echo "phpMyAdmin successfully updated"
    rm $TAR_FILE
    echo $LATEST > current
    echo "All done"
fi

It's only fair to share...Tweet about this on TwitterShare on Google+Share on FacebookShare on TumblrEmail this to someone

前にもMySQLのバックアップスクリプトを紹介することはありましたけど、あれからバックアップのサイズがどんどん増えて、FTPサーバーの容量状態はちょっと厳しくなってしまいました。ですから、今回の新しいスクリプトにはまず、圧縮機能を追加しました

それに、その古いスクリプはwputを利用してファイルをftpで転送したから、とても不安全でした。だからついでに、今度はlftpを利用してftpsで転送します。もちろんどうしても必要なら、ftpでもおkです。スクリプでFTP_PROTOCOLを指定したらいいです
それからもし自分のサインした証明証を使っていますなら、

set ssl:verify-certificate no

を/etc/lftp.conf追加することを忘れないように

更に、今回はバックアップファイルを強制的にアップロードするためのスクリプトを提供しました。

/PATH/TO/BACKUP/MySQL_Backup/script/force_upload.sh N

を実行したら、N日間前のファイルをアップロードできます

続きを読む

It's only fair to share...Tweet about this on TwitterShare on Google+Share on FacebookShare on TumblrEmail this to someone

今日で出した2015年4月の更新の中、KB3022345は正常にインストール出来ません。

詳しいのはMSコミュニティへ:リンク

これって何回目だろうなぁ、Windows Updateが問題出るのは・・・まぁ、今回もまた待つしかできませんよね。まだ更新してない各位も少々待つほうがいいと思います。

解決方法:
この問題の解決方法は、一応KB3045999をアンインストールして、再起動せずにKB3022345をインストールしたらいんだ。その後再起動して、もう一度KB3045999インストールして、これで解決完了です。
Windows 8.1 x64バージョンのアップデートプログラムのダウンロード先:KB3045999KB3022345
Server 2012R2 x64バージョン:KB3045999KB3022345

It's only fair to share...Tweet about this on TwitterShare on Google+Share on FacebookShare on TumblrEmail this to someone

元々https://github.com/suin/phpstorm-yaf-docからのdocをいつも使ってたけど、このプロジェクトの最後の更新はとても遠い昔のことですから、ミスがいっぱいあるので、今回ようやく張り切って自分でやり直そうと思ってのに、ちょっとGitHubで「yaf doc」を検索したら、まさかこのdocよりずっと良いyafのPHPDocを見つけっちゃったの

そのリンクは:
https://github.com/elad-yosifon/php-yaf-doc

やっと決意をしたのに、ちょっとあれだよね・・・(この得したくせに損した顔をする奴めワロタ)