手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表2013年12月的文章

magento 后台为链接加上key

这年头,什么都不可靠。所幸,我还不需要用黄瓜。

在使用magento的时候,由于要使用ajax,但我又不想将这些链接加入到菜单里(加到菜单的链接会自动加入key参数),所以一直都是出现了自动跳转的问题。在这里面我要说一下。如果你使用原生的prototype.js,你用ajax的post功能时,即使不带key参数,也是可以正常处理的。如果是jquery..即使你带了key参数。也不能post,只能get。。。。苦逼
 
那么,如果在URL上加入key参数呢。大家都知道key参数是magento后台用来与前台分开的,里面带入了安全性的处理。可是怎么加上这个key呢?搜索了一下google居然没有一个文章是介绍这玩意的。当然也可能我的关键字不正确。
 
求人不如求已,打开代码,搜索key,很快就发现了Mage::getSingleton("adminhtml_url")这个玩意,里面有一个getUrl。。哇塞,可以直接生成带key的URL。看了一下。直接使用在程序里,确实生成了URL。并且可以通过浏览器访问。
 
记录一下

转:How can I trigger a notification from a remote terminal in OS X

其实这篇文章中的内容在之前我已经有引用过了,就是早先的监控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.

  1. Send yourself an email. If sendmail is configured on the server, you could do

    ./long_process && echo "Job done" | sendmail pnj@yourdomain.com 
  2. 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.

  3. 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。

 

转:使用 MacBook Pro 的硬件重置功能解决故障

 备份性的文章,所以先不管三七二十一就CP过来,最起码这篇文章是2012年的,短时间内应该还是有效的

 
原文来自:https://dong.io/201202/fix-your-macbook-pro-by-reset-hardware/
 

今天发现新买的MacBook Pro的一个USB口异常。具体表现是连接到移动硬盘之后,硬盘灯闪亮但是Mac无任何反映。而且,iPhone也无法通过此USB口充电或数据传输。经过Google,找到了下面的步骤来解决:

  • 关闭电脑。
  • 按住SHIFT+CTRL+OPTION+POWER十秒钟
  • 按住OPTION+CMD+R+P+POWER,Mac会不断重启而不进入操作系统,四次(官方说三次)之后松开
  • 正常开机即可

然后USB口就正常了。事后从Apple的官方文档中找到了这些组合键的作用,并且发现上述步骤其实是两个不同的重置操作。

SHIFT+CTRL+OPTION+POWER十秒钟:重置系统管理控制器(SMC)

  • 关闭电脑。
  • 将 MagSafe 电源适配器连接到电源和 Mac(如果尚未连接的话)。
  • 在内建键盘上,同时按下(左侧)Shift-Control-Option 键和电源按钮。
  • 同时松开所有键和电源按钮。
  • 按电源按钮打开电脑。

:重置 SMC 时,MagSafe 电源适配器上的 LED 指示灯可能会更改状态或暂时关闭。

在风扇、电源指示灯、系统性能、视频出现某些异常时候,可以通过上述方法进行重置来解决。具体的症状判断和说明可以参考"基于 Intel 的 Mac:重置系统管理控制器(SMC)"。

OPTION+CMD+R+P+POWER:重置NVRAM 或 PRAM

Mac 会将某些设置储存在特殊内存区域中,而且即使关机这些设置也不会丢失(除非存在电池问题)。 在基于 Intel 的 Mac 上,存储位置是称为 NVRAM 的内存;而在基于 PowerPC 的 Mac 上,存储位置则是称为 PRAM 的内存。操作步骤为:

  • 关闭电脑。
  • 在键盘上找到以下按键:Command、Option、P 和 R。您需要在步骤 4 中同时按下这些键。
  • 启动电脑。
  • 按住 Command-Option-P-R 键。必须在出现灰屏前按下此组合键。
  • 按住上述键,直到电脑重新启动,您会再次听到启动声。
  • 松开这些键。

在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.

  1. I fixed this the following way (this is basically resetting the Power Management Unit — PMU):
  2. I disconnected the computer from the power cord, and from all other cables.
  3. I held down the power button for several seconds to turn off the computer.
  4. I let it sit 5 minutes.
  5. I restarted the laptop while holding down the Shift key.  This restarted the computer in Safe Mode, with the screen visible again.
  6. After I logged in (in Safe Mode) to make sure everything was ok, I simply restarted the computer the normal way, and the screen behaved normally again.

=================================

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)

微信菜单的实现代码

 不多说,上代码。有几个要注意的(这段代码是我从我的系统里剥出来的。写了很久了,只是最近有人一直在问,我想,这也不是什么特别的代码,还是开源吧。)

1、请求微信菜单需要token,所以要事先生成。这个token其实可以用不少时间的,看官方接口(token调用生成,每天是有次数的,所以节约着用,能存本地就存本地吧,记录下过期时间即可)
2、子菜单的数组顺序就是微信的子菜单:从上至下的顺序 。这个不要搞错
3、子菜单是有数量限制的
4、主菜单是有字数限制的。不能超过4个中文字。
 
上代码吧:
PHP代码
  1. <?php  
  2. /** 
  3.  * @category menu.php 
  4.  * @author   gouki <gouki.xiao@gmail.com> 
  5.  * @created  2013-10-16 15:14 
  6.  * @since 
  7.  */  
  8. $menudata = array(  
  9.     'button' => array(  
  10.         array(  
  11.             'name'       => '菜单一',  
  12.             'sub_button' => array(  
  13.                 array(  
  14.                     'type' => 'click',  
  15.                     'name' => '最上方子菜单1',  
  16.                     'key'  => 'R:4:1',  
  17.                 ),  
  18.                 array(  
  19.                     'type' => 'click',  
  20.                     'name' => '下方菜单',  
  21.                     'key'  => 'R:3:1',  
  22.                 ),  
  23.             )  
  24.         ),  
  25.         array(  
  26.             'name'       => '菜单2',  
  27.             'sub_button' => array(  
  28.                 array(  
  29.                     'type' => 'click',  
  30.                     'name' => '第一个',  
  31.                     'key'  => 'R:2:1',  
  32.                 ),  
  33.                 array(  
  34.                     'type' => 'click',  
  35.                     'name' => '第二个',  
  36.                     'key'  => 'R:8:1',  
  37.                 ),  
  38.                 array(  
  39.                     'type' => 'click',  
  40.                     'name' => '第三个',  
  41.                     'key'  => 'R:9:1',  
  42.                 ),  
  43.                 array(  
  44.                     'type' => 'click',  
  45.                     'name' => '第四个',  
  46.                     'key'  => 'R:10:1',  
  47.                 ),  
  48.             )  
  49.         ),  
  50.         array(  
  51.             'type' => 'click',  
  52.             'name' => '菜单3',  
  53.             'key'  => 'M:7',  
  54.         ),  
  55.     )  
  56. );  
  57. $menujson = json_encode($menudata, JSON_UNESCAPED_UNICODE);  
  58. define('APPKEY'''); //这里是APPKEY  
  59. define('SECRET'''); //SECRET ....  
  60. $getTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";  
  61. $getTokenUrl = sprintf($getTokenUrl, APPKEY, SECRET);  
  62. $result = json_decode(file_get_contents($getTokenUrl), true);  
  63. $token = '';  
  64. if (isset($result['access_token'])) {  
  65.     $token = $result['access_token'];  
  66. }  
  67. if (!$token) {  
  68.     throw new Exception('token can not empty');  
  69. }  
  70.   
  71. $createMenuUrl = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=' . $token;  
  72. $opts = array(  
  73.     'http' => array(  
  74.         'method'  => 'POST',  
  75.         'header'  => "Content-type: application/x-www-form-urlencodedContent-Length: " . strlen($menujson) . "" . "Connection: keep-alive" . "Keep-Alive: " . 300 . "",  
  76.         'content' => $menujson,  
  77.         'timeout' => 120,  
  78.     ),  
  79. );  
  80.   
  81. $context = stream_context_create($opts);  
  82. $response = json_decode(file_get_contents($createMenuUrl, false, $context),true);  
  83.   
  84. if(!$response['errcode'] ){  
  85.     echo "success";  
  86. }else{  
  87.     echo $response['errmsg'];  
  88. }  
  89.   
  90. echo "<pre>";  
  91. print_r($response);  
  92. echo "</pre>";  
记得。如果返回成功,你又看不到效果,可以将公众号先取消关注,再加为关注,立刻就能看到效果了。
否则,你要等24小时左右 才能看到效果。
 
顺便,我也可以承接微信开发(请不要咨询我微信开发怎么做,网上教程很多。。。)

ltc监控脚本

 最近BTC和LTC很火啊。。但我又没有时间关注它,所以就写了个脚本,利用macosx 的notification来提醒。其实有很多办法,比如chrome的桌面提醒等。windows的messmage,邮件都OK

 
我这个只是最简单的版本,花了5分钟写完。。用了一些技术:
1、php
2、crontab 
3、terminal-notifier (这个是ruby的,在mac下面安装也很简单,直接brew install terminal-notifier 就OK了)
 
上代码:
PHP代码
  1. if (count($argv) == 1) {  
  2.     echo "\nUse age:\n\n";  
  3.     echo "php okcoin.php --ltc=100 --btc=500 \n\n";  
  4.     echo "--ltc 代表参数,ltc和btc不分顺序\n\n";  
  5.     exit;  
  6. }  
  7. array_shift($argv);  
  8. $params = array();  
  9. foreach ($argv as $val) {  
  10.     if (strncasecmp($val"--", 2) === 0) {  
  11.         $p = explode("="substr($val, 2));  
  12.         if (!isset($p[1])) {  
  13.             continue;  
  14.         }  
  15.         $params[trim($p[0])] = trim($p[1]);  
  16.     }  
  17. }  
  18. if(!$params){  
  19.     exit("参数不正确");  
  20. }  
  21. $api = "https://www.okcoin.com/ticker.do?random=" . rand(1, 9);  
  22. $data = @json_decode(file_get_contents($api), true);  
  23.   
  24. $warning = array(  
  25.     'btc' => 5000,  
  26.     'ltc' => 150,  
  27. );  
  28.   
  29. if ($data) { //证明是正常数据  
  30.     $btcLast = $data['btcLast'];  
  31.     $ltcLast = $data['ltcLast'];  
  32.     if (isset($params['btc']) && $btcLast <= $params['btc']) {  
  33.         exec("terminal-notifier -message '关注一下BTC,价格在指定价位附近了' -title 'BTC 警告'");  
  34.     }  
  35.     if (isset($params['ltc']) && $ltcLast <= $params['ltc']) {  
  36.         exec("terminal-notifier -message '关注一下LTC,价格在指定价位附近了' -title 'LTC 警告'");  
  37.     }  
  38. }  
  39. exit;  
自用,只是够用就好

Tags: ltc

Records:612