Alexa, ask UA Campus Rec when does the gym open?

I built an Alexa Skill, and got it published.

How I Learned Alexa Skill Kit and Why I Picked it Up Again

I learned about Alexa Skill Kit at Hack Arizona 2017, and built an incredibly complicated 520bus skill to query departure times of Sun Tran buses and Sun Link modern streetcar. I didn't win a prize, and quickly forgot about that.

A few months later, a tweet caught my attention: publish a skill, get an Echo Dot & Alexa dev swag. I always wanted to own a hardware device that integrates with Alexa. I considered the "practically free" Dash Wand, but gave up when I found out it is powered by batteries. I couldn't afford to buy an Echo, because I already spent all my money on those ESP8266 toys. However, I'm not going to miss a FREE Echo Dot.

How to Deduplicate BibTeX Entries?

I'm writing my dissertation recently. My dissertation is a combination of several publications from my PhD career. Therefore, part of my dissertation writing process involves copy-pasting the papers together into a single document.

Like any good academics, I typeset my publications with LaTeX, and use BibTeX to incorporate citations into the documents. My collection of bibliographies is fairly ad hoc: during each writing project, I search for related work to cite in my paper. Unlike most others, I create a separate bib file for each BibTeX entry named after the citation key. For example, I would have bib/ndn-tlv.bib for a BibTeX entry named "ndn-tlv", and bib/Mininet.bib for the "Mininet" entry. This allows me to find available citation keys with a quick glance over the bib/ directory. My build process then concatenates these small bib files into ref.bib as an input to BibTeX.

My dissertation combines all my publications, and thus needs a union of BibTeX entries from those combinations. To make this union, I can copy all these single-entry bib files into the same directory. If two previous papers cited the same reference, their bib files should have the same name, and only one copy would be left in the combined directory.

Except that the above assumption is true only if I cited the same reference with the same citation key. And so I discovered a citation appearing twice in my dissertation:

duplicate references in dissertation

yoursunny.com is in Git and Completely Rebuilt

I started making websites since 2001. This website, yoursunny.com, started in 2006. In the past 11 years, I've rebuilt the site several times, switched from ASP to PHP, and moved from Windows dedicated hosting to shared hosting and eventually to Linux VPS. So far, every time I want to perform a major edit to the website, I copy original versions of affected files to a backup folder on my computer, and then go ahead to do the edit. After having tested the modification locally, I upload changed files via FTP or SFTP to the server. One constant worry over my head is, what if I lose all the files on my computer, and my hosting provider vanishes so I can't get them back? Another headache is, sometimes I may make an edit incorrectly, but I couldn't revert it back because I didn't copy the original files to the backup folder as I determined the change wasn't "major" enough to warrant a backup.

During my studies at University of Arizona, I learned a useful tool called git. Git is a source control system: it allows developers to create a repository and put source code into the repository, and will automatically keep track of all the edits applied to each file. By putting website source code into a git repository, I can find out what modifications I've performed to each file over time, regardless of whether it is "major" or "minor". Additionally, I can synchronize the git repository with a remote git server, so that the server has a copy of my website, including edit histories as well. This would solve both the worry of losing files, and the headache of not having an earlier version to revert to in case of an incorrect modification.

After delaying this projects several times, I am finally determined to move yoursunny.com into git repositories in Apr 2017. At the same time, to keep the website source code as clean as possible, I decide to try out two new technologies: static site generators and Composer. That is, I would rebuild yoursunny.com, copying page by page, into a new website stored in git repositories.

I spent about 2 months for this rebuild/move, and I'm happy to announce that yoursunny.com is now under source control.

Main Site with Composer

base64加密PHP脚本的解码方法

PHP是网站服务端最流行的编程语言之一。PHP运行环境本身是开源的,服务器不加载插件时PHP脚本也无法加密。但是,总有人因为商业上的考虑,而将PHP程序通过各种方法进行混淆,使读者很难看到清晰易懂的代码。

然而,PHP运行环境的本质决定了,被混淆、编码的PHP脚本总是有办法恢复成可读的代码的。本文介绍了一种对含有eval和base64_decode的、被加密的PHP的解码方法。

在使用这种方法之前,你应该准备好:

  • 能运行PHP的Web服务器,例如 Apache 或 IIS
  • wget.exe命令行客户端 或 浏览器
  • 具备PHP语法高亮功能的文本编辑器,例如 Notepad2

下载每一步的源代码

dbMySQL数据源访问类

dbMySQL类,用于PHP访问MySQL数据库,而编程更加方便、安全性更高。

<?php
class dbMySQL {//数据源访问类
    private $conn;//连接
    private $prefix;//表名前缀
    private $sql=NULL;//上一条SQL语句
    private $result=NULL;//结果
    private $rows=0;//行数
    private $rows_got=0;//已提取行数
    //$db=new dbMySQL(主机,用户名,密码,数据库名,表名前缀,是否永久连接);
    function __construct($host,$username,$password,$dbname,$prefix='',$pconnect=TRUE) {//连接
        $connect_function=$pconnect?'mysql_pconnect':'mysql_connect';
        $this->conn=@$connect_function($host,$username,$password) or die('不能连接到MySQL数据源服务');
        mysql_query("SET NAMES 'utf8'",$this->conn);
        @mysql_select_db($dbname,$this->conn) or die('MySQL数据源中数据库不存在');
        $this->prefix=$prefix;
    }
    private function close() {//如果上一个结果存在,清除它
        if ($this->result!=NULL) mysql_free_result($this->result);
    }
    public function execute_sql($SQL) {//执行
        //echo $SQL;
        $this->close();
        $this->sql=$SQL;
        mysql_query($SQL,$this->conn);
        $err=mysql_error($this->conn); if ($err!='') die($err);
        $this->result=NULL;
        $this->rows=mysql_affected_rows($this->conn);
        $this->rows_got=0;
    }
    public function execute($SQL,$p=NULL,$prefix='###') {//带参数执行
        $s=str_replace($prefix,$this->prefix,$SQL);
        if ($p==NULL) { $this->execute_sql($s); return; }
        foreach ($p as $i => $v) {
            if (ctype_digit($i{0}) && !is_numeric($v)) die('SQL数值型参数错误 '.$i.'=>'.$v);
            $vv=ctype_lower($i{0})?"'".mysql_escape_string($v)."'":$v;
            $s=str_replace('?'.$i,$vv,$s);
        }
        $this->execute_sql($s);
    }
    //带参数执行、查询说明
    //数组$p "a"->"ppp"
    //SELECT * FROM j WHERE m=?a 解析为 SELECT * FROM j WHERE m='ppp'ִ
    //参数名称第一位是小写字母,作为字符型参数,编码并加单引号
    //参数名称第一位是数字,作为数字型参数,如果不是数字就出错
    //参数名称第一位是其他情况,直接带入SQL表达式
    //$prefix表示前缀占位符,默认###,FROM ###kk在前缀是pr_时解析为FROM pr_kk
    public function query_sql($SQL) {//查询
        //echo $SQL;
        $this->close();
        $this->sql=$SQL;
        $this->result=mysql_query($SQL,$this->conn);
        $err=mysql_error($this->conn); if ($err!='') die($err);
        $this->rows=mysql_num_rows($this->result);
        $this->rows_got=0;
    }
    public function query($SQL,$p=NULL,$prefix='###') {//带参数查询
        $s=str_replace($prefix,$this->prefix,$SQL);
        if ($p==NULL) { $this->query_sql($s); return; }
        foreach ($p as $i => $v) {
            if (ctype_digit($i{0}) && !is_numeric($v)) die('SQL数值型参数错误 '.$i.'=>'.$v);
            $vv=ctype_lower($i{0})?"'".mysql_escape_string($v)."'":$v;
            $s=str_replace('?'.$i,$vv,$s);
        }
        $this->query_sql($s);
    }
    public function read() {//提取一行为关联数组,如果已提取完则返回NULL
        if ($this->result==NULL) return NULL;
        if ($this->rows_got==$this->rows) return NULL;
        ++$this->rows_got;
        return mysql_fetch_assoc($this->result);
    }
    public function num_rows() {//总行数
        return $this->rows;
    }
    public function eof() {//是否提取完了?
        return ($this->rows_got==$this->rows);
    }
}
?>