总体来说,2013年(不按自然年计算,按传统农历计算)发生了很多事情。
膘叔的简单人生
总体来说,2013年(不按自然年计算,按传统农历计算)发生了很多事情。
本来,我以为网上的笑话真心是笑话:晚上睡觉的时候忘关4G,结果早上起来房子属于中国移动了(是按40元300M流量,这个套餐3秒就能用完,3秒40元,一分钟800元,一个小时4万8,你算算24小时多少钱)
结果我就真的遇到了。前两天在利用wifi更新APP的时候,因为上厕所所以wifi断了,结果就自动用4G下载了。原本我还有100多M流量,可是小号的时候就拼命收到短信。等结束后看的时候,发现提示流量超出100M,共扣了我64元。我靠,这才一分钟左右。
仔细算了算,我后来余额查询发现被扣了90多块。这,这,这TMD真心玩不起啊。得,我还是把4G关掉吧,安心使用EDGE算了。
今天在apt-get upgrade的时候 。发现说我的libxx.so不是最新版,应该移到i386-xx-gnu目录外面去。于是。我mv xxxx.so 到外面目录 ,然后就发生了惊天动地的事情。
当时我没移动前,它的提示是这样的:
A copy of the C library was found in an unexpected directory:
'/lib/i386-linux-gnu/libc-2.15.so'
It is not safe to upgrade the C library in this situation;
please remove that copy of the C library or get it out of
'/lib/i386-linux-gnu' and try again.
看了上面的提示,我觉得我应该移动啊。可移动之后,执行很多命令都显示:
ls: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
几乎任何 命令都是这个错。在vampire的提示下,说是busybox可以操作。于是我想cp回去:
busybox cp libc-2.15.so ./i386-linux-gnu/
cp: can't create './i386-linux-gnu/libc-2.15.so': Permission denied
哎呀。我正好不是ROOT权限,这回凄凉了
重启进入recovery模式,但任何都进不了。提示的都是:
这,这怎么办?于是,我重新下载了新的debian的ISO,准备装个虚拟机,再加载这个虚拟盘。
半小时后,我下载完了debian的ISO,并装好虚拟机,
在安装虚拟的过程中,我针对原来的虚拟机,也加载了 ISO,准备利用安装的时候,调用exec shell来处理,但,死活找不到硬盘。可能是因为虚拟机的原因?好吧,还是安心用第二个虚拟机吧
打开新的debian的虚拟机,然后开始加载盘,加载完后,看一下先?
运行fdisk -l
真的有,于是我直接mount,不料
然后指定为ext2,ext3,ext4都不OK,vampire说。lvm不能这样处理。于是让我用vgscan,lvscan查看一下,但命令不存在,于是执行:apt-get install lvm2
再运行lvscan:
果然有了,于是:
前段时间没有任何博客写,是因为我去香港逛了一圈。
这年头,什么都不可靠。所幸,我还不需要用黄瓜。
其实这篇文章中的内容在之前我已经有引用过了,就是早先的监控ltc的脚本。当然现在ltc已经堕落了。。
看标题也可以知道我们想做些什么。所以看看老外们是怎么做的好了,原文在:http://superuser.com/questions/645036/how-can-i-trigger-a-notification-from-a-remote-terminal-in-os-x
You have not specified what kind of notification you want nor what OS the remote server is running so I am going to have to make some assumptions here. I will assume you don't really care what type of notification it is as long as you are notified and that the remote server is running some flavor of *nix.
Send yourself an email. If sendmail is configured on the server, you could do
./long_process && echo "Job done" | sendmail pnj@yourdomain.com
ssh back to your local machine (assuming this is possible) and make it talk to you. See here for more cool ways of making OSX beep at you.
./long_process && ssh you@local.ip say "Yo! All done"
or
./long_process && ssh you@local.ip terminal-notifier -message "Job finished!" -title "Info"
If you are connecting from a dynamic IP and you have configured your router so that you can ssh to that dynamic IP, you can do this (assuming you are only currently connected from your remote machine):
ip=$(who | grep $USER | perl -lne 's/\\((.+?)\\)\s*$//; print "$1"' | tail -n 1) && ./long_process && ssh you@$ip terminal-notifier -message "Job finished!" -title "Info"
You can set up password-less ssh in the normal way. It should not be affected by the dynamic IP. Once you have done so, the code above will work.
Use pushover and send a notification to your Android or iOS device (if you have one)
./long_process && pushover.pl "All done"
---EOF--
这里面有很多方便,但其中的一种就是terminal-notifier。
备份性的文章,所以先不管三七二十一就CP过来,最起码这篇文章是2012年的,短时间内应该还是有效的
今天发现新买的MacBook Pro的一个USB口异常。具体表现是连接到移动硬盘之后,硬盘灯闪亮但是Mac无任何反映。而且,iPhone也无法通过此USB口充电或数据传输。经过Google,找到了下面的步骤来解决:
然后USB口就正常了。事后从Apple的官方文档中找到了这些组合键的作用,并且发现上述步骤其实是两个不同的重置操作。
SHIFT+CTRL+OPTION+POWER十秒钟:重置系统管理控制器(SMC)
注:重置 SMC 时,MagSafe 电源适配器上的 LED 指示灯可能会更改状态或暂时关闭。
在风扇、电源指示灯、系统性能、视频出现某些异常时候,可以通过上述方法进行重置来解决。具体的症状判断和说明可以参考"基于 Intel 的 Mac:重置系统管理控制器(SMC)"。
OPTION+CMD+R+P+POWER:重置NVRAM 或 PRAM
Mac 会将某些设置储存在特殊内存区域中,而且即使关机这些设置也不会丢失(除非存在电池问题)。 在基于 Intel 的 Mac 上,存储位置是称为 NVRAM 的内存;而在基于 PowerPC 的 Mac 上,存储位置则是称为 PRAM 的内存。操作步骤为:
在NVRAM和PRAM中保存着很多硬件的配置,并且不会因为关机而丢失。详细的信息可以参考"重置 Mac 的 PRAM 和 NVRAM","何时要重置 NVRAM 或 PRAM","Mac OS X:PRAM 中存储的是什么"。
当Mac遇到电源和硬件的异常的时候,如果不是外伤则可以考虑进行重置(谨慎,推荐事先咨询天才吧技术人员),如:不能打开、不能从睡眠状态中唤醒、不能给电池充电、不能看到AC适配器,在连接AC适配器后被电击,USB失灵等。另外Power系列和Intel系列还存在着操作上的差异。
但是目前不清楚哪个重置操作解决了USB口失灵的问题;其次不清楚这些重置是否有其他副作用。
-----
话说,这里还有一个英文版:http://www.ruddwire.com/1017/tech/macbook-pro-turns-on-but-screen-stays-black-my-solution/#.Uq5owmRF56A
解决了一个小问题:macbook pro turns on but screen stays black — my solution
The Apple Macbook Pro would turn on, but the screen would not. The screen would stay black. I could tell the computer was on because when I hit the “caps lock” key, the green light on the key would turn on and off.
=================================
If that doesn’t work for you, you could try these steps, documented at apple.com:
Holding down Command, Option, P, and R to reset your PRAM and NVRAM
Resetting PowerBook and iBook Power Management Unit (PMU)
不多说,上代码。有几个要注意的(这段代码是我从我的系统里剥出来的。写了很久了,只是最近有人一直在问,我想,这也不是什么特别的代码,还是开源吧。)
<?php
/**
* @category menu.php
* @author gouki <gouki.xiao@gmail.com>
* @created 2013-10-16 15:14
* @since
*/
$menudata = array(
'button' => array(
array(
'name' => '菜单一',
'sub_button' => array(
array(
'type' => 'click',
'name' => '最上方子菜单1',
'key' => 'R:4:1',
),
array(
'type' => 'click',
'name' => '下方菜单',
'key' => 'R:3:1',
),
)
),
array(
'name' => '菜单2',
'sub_button' => array(
array(
'type' => 'click',
'name' => '第一个',
'key' => 'R:2:1',
),
array(
'type' => 'click',
'name' => '第二个',
'key' => 'R:8:1',
),
array(
'type' => 'click',
'name' => '第三个',
'key' => 'R:9:1',
),
array(
'type' => 'click',
'name' => '第四个',
'key' => 'R:10:1',
),
)
),
array(
'type' => 'click',
'name' => '菜单3',
'key' => 'M:7',
),
)
);
$menujson = json_encode($menudata, JSON_UNESCAPED_UNICODE);
define('APPKEY', ''); //这里是APPKEY
define('SECRET', ''); //SECRET ....
$getTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
$getTokenUrl = sprintf($getTokenUrl, APPKEY, SECRET);
$result = json_decode(file_get_contents($getTokenUrl), true);
$token = '';
if (isset($result['access_token'])) {
$token = $result['access_token'];
}
if (!$token) {
throw new Exception('token can not empty');
}
$createMenuUrl = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=' . $token;
$opts = array(
'http' => array(
'method' => 'POST',
'header' => "Content-type: application/x-www-form-urlencodedContent-Length: " . strlen($menujson) . "" . "Connection: keep-alive" . "Keep-Alive: " . 300 . "",
'content' => $menujson,
'timeout' => 120,
),
);
$context = stream_context_create($opts);
$response = json_decode(file_get_contents($createMenuUrl, false, $context),true);
if(!$response['errcode'] ){
echo "success";
}else{
echo $response['errmsg'];
}
echo "<pre>";
print_r($response);
echo "</pre>";
记得。如果返回成功,你又看不到效果,可以将公众号先取消关注,再加为关注,立刻就能看到效果了。
最近BTC和LTC很火啊。。但我又没有时间关注它,所以就写了个脚本,利用macosx 的notification来提醒。其实有很多办法,比如chrome的桌面提醒等。windows的messmage,邮件都OK
if (count($argv) == 1) {
echo "\nUse age:\n\n";
echo "php okcoin.php --ltc=100 --btc=500 \n\n";
echo "--ltc 代表参数,ltc和btc不分顺序\n\n";
exit;
}
array_shift($argv);
$params = array();
foreach ($argv as $val) {
if (strncasecmp($val, "--", 2) === 0) {
$p = explode("=", substr($val, 2));
if (!isset($p[1])) {
continue;
}
$params[trim($p[0])] = trim($p[1]);
}
}
if(!$params){
exit("参数不正确");
}
$api = "https://www.okcoin.com/ticker.do?random=" . rand(1, 9);
$data = @json_decode(file_get_contents($api), true);
$warning = array(
'btc' => 5000,
'ltc' => 150,
);
if ($data) { //证明是正常数据
$btcLast = $data['btcLast'];
$ltcLast = $data['ltcLast'];
if (isset($params['btc']) && $btcLast <= $params['btc']) {
exec("terminal-notifier -message '关注一下BTC,价格在指定价位附近了' -title 'BTC 警告'");
}
if (isset($params['ltc']) && $ltcLast <= $params['ltc']) {
exec("terminal-notifier -message '关注一下LTC,价格在指定价位附近了' -title 'LTC 警告'");
}
}
exit;
自用,只是够用就好
搜索了一些网上的教程,发现网上对于自定义的判断,都是说加个字段或者基于prototype来进行判断就可以了。什么require-text代表必填 之类的。这段时间在对magento做处理的时候发现这样的判断好痛苦(好象,我是指基于产品的FORM的扩展),如果是自己做二次开发,自己写表单,当然这样就OK了
翻看了一下程序,我开始看到资料就是指require-text之类的扩展,那我想,我只要能够加入一个class属性,我就可以基于这个class属性进行判断了,不是吗?
于是我找到了模版的layout,重新定义了layout,表示我可以引入一个指定的js文件,或者引入了代码。
然后,我找到了dispatchEvent,发现有一个事件,但我看了下,在这个事件里我几乎没有什么事情可以做【不过,基于这个事件,我把SKU,日期等做成了自动生成,只是他对表单的验证并没有什么帮助】
找了半天,最后发现数据库有一个backend_model,原来可以为这些程序指定事件,发现SKU有一个事情,是判断 sku的长度不能超过N个字符的,于是对着这个model进行了测试,发现果然OK。添加了几个model,然后update一下数据库,一切就完成了