Submitted by gouki on 2017, February 6, 4:17 PM
接上一篇:买了台阿里云的内网 的内容
上一篇中,我采用了nginx来转发http代理 的请求,但这里有个问题就是,如果你要请求的是https的数据,上面的配置就不方便了
于是祭出了ssh -D 大法,在内网里使用ssh -D xxxx 公网IP 。然后使用polipo来设置成http_proxy和https_proxy代理
polipo安装很简单:apt-get install polipo
修改/etc/polipo/config,加入两行
socksParentProxy = localhost:上面的xxx
socksProxyType = socks5
再将~/.bashrc中的http_proxy改为 http_proxy=127.0.0.1:8123 (8123是polipo的默认端口),再加一条https_proxy,数据一样
只是ssh -D ,会连接上远程服务器,有点麻烦。总不能不关窗口吧?再祭出screen。于是都解决了
screen -S sshd
然后ctrl+a d 退出来就OK了
再试着请求wget https://getcomposer.org/installer,顺利下载并安装好
----EOF---
后记:如果你不请求https数据,那么用nginx就够了。
苹果相关 | 评论:1
| 阅读:16605
Submitted by gouki on 2017, February 5, 11:12 AM
几个小笔记,自己处理一下
10.171.x.x 是外网机器 的内网IP
10.29.x.x 是内网机器 的IP
#在外网机器上加入这些iptables
iptables -t nat --flush
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to-destination 10.29.x.x:22
iptables -t nat -A POSTROUTING -d 10.29.x.x -p tcp --dport 22 -j SNAT --to 10.171.x.x
iptables-save > /etc/iptables.up.rules
echo "pre-up iptables-restore < /etc/iptables.up.rules" > /etc/network/interface
--------上面这段是支持直接用2222端口连接入内网
在外网机器 的nginx加入以下配置,设置HTTP代理
server {
listen 9999 ;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
resolver 114.114.114.114;
proxy_pass http://$http_host$request_uri;
}
}
----------
在内网机器里加入:
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export http_proxy=http://10.171.212.249:9999
修改:/etc/apt/source.list 为 ustc.edut.cn的源
deb http://mirrors.ustc.edu.cn/debian stable main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian stable main contrib non-free
deb http://mirrors.ustc.edu.cn/debian stable-updates main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian stable-updates main contrib non-free
# deb http://mirrors.ustc.edu.cn/debian stable-proposed-updates main contrib non-free
# deb-src http://mirrors.ustc.edu.cn/debian stable-proposed-updates main contrib non-free
deb http://mirrors.ustc.edu.cn/dotdeb jessie all
deb-src http://mirrors.ustc.edu.cn/dotdeb jessie all
------------
添加了dotdeb的源后,需要处理一下(官网是https,其实也支持http)
wget http://www.dotdeb.org/dotdeb.gpg
cat dotdeb.gpg | apt-key add -
--------
至此,全部完成。由于有http_proxy,现在curl/wget,默认都可以用代理 了。只是https的不行。先这样了
Tags: http_proxy
苹果相关 | 评论:0
| 阅读:16380
Submitted by gouki on 2017, January 27, 12:03 AM
When I tried to build and run, Xcode said my device was locked. I looked at my iPhone, and it's not locked at all....possible bug? How do I fix this?
1.Did you by chance not "trust" the device? This will prevent it from communicating with xcode even if the device is unlocked.
2.Unplug the device, close xcode, and then open xcode and plugin the device. When you plug it in (after unlocking it) it you should be prompted to "trust" the computer (in the iOS device). My guess is you may have accidentally tapped "do not trust" and so the device will refuse to connect to the computer.
3.Lock the device,Remove cable from device.,Unlock the device,Connect again to Mac
Flutter | 评论:0
| 阅读:17341
Submitted by gouki on 2017, January 25, 10:07 PM
nestable在点击的时候,有一个拖动的状态被触发,会导致你给nestable上加的链接都会无效。
只要在最外层的li里加入一个class为:dd-nodrag,就不会被触发了。然后你在子菜单中就可以为它们加入工具菜单了,比如编辑 、删除等。
又或者,你加入dd-handle,这样的话,只能点击最左侧的handle部位才能被拖动
参考 :http://dbushell.github.io/Nestable/ 最下面
Javascript | 评论:0
| 阅读:21622
Submitted by gouki on 2017, January 18, 9:48 AM
一个很简单的laravel代码:
PHP代码
- User::where('id',1)->update(['last_login'=>time()]);
这样一个简单的代码,你会发现,它并没有触发:updating,updated事件,然而,你又会发现,updated_at也更新了。这是怎么回事?
跟进代码看一下,你会发现这个update,是Eloquent\Builder的方法,它的update方法代码很简单:
PHP代码
-
-
-
-
-
-
- public function update(array $values)
- {
- return $this->toBase()->update($this->addUpdatedAtColumn($values));
- }
我擦 ,要不要这么直接?再看一下toBase,这回是调用的是Query\Builder了。这里的update,就纯粹是生成sql,然后execute,不再走EloquentORM的事件了,所以就不会触发任何事件。
那么要怎么样才能触发事件呢?方法有两种
1、不要这样简写:先读数据再update,就一定会触发
2、不要用where(),而是直接User::find(1)->update([]),这时候就会从ORM走了。
这事儿官方有解释:
https://laravel.com/docs/5.3/eloquent#updates
- When issuing a mass update via Eloquent, the saved and updated model events will not be fired for the updated models. This is because the models are never actually retrieved when issuing a mass update.
同时,这事儿在stackoverflow上也有很多人在问,有人回复的就是和我上面的一样:
http://stackoverflow.com/questions/41295032/laravel-eloquent-model-update-event-is-not-fired
- You need to retrieve the user from the database and then save that user in order to fire the event. For example:
-
- This will NOT fire the update event:
-
- User::where('id', $id)->update(['username' => $newUsername]);
- This will fire the update event:
-
- User::find($id)->update(['username' => $newUsername]);
官方的解释我是看过了,下面的是我用了很多办法没法解决后才找到的。
我在想,use SoftDeletes可以注入代码,为什么我不行?直到我发现softdeletes是官方自带库,人家都准备了事件:onDelete了。。怎么就没有onUpdate事件可以让我加点字段呢?
然后我又想用其他的Scope,也没有成功(折腾了一个下午)
暂时放弃!就这样吧,不过我还在想想,有没有什么办法可以注入,因为在sql生成完后,它还是有触发的事件的,比如:
PHP代码
-
-
-
-
-
-
-
-
- public function logQuery($query, $bindings, $time = null)
- {
- if (isset($this->events)) {
- $this->events->fire(new Events\QueryExecuted(
- $query, $bindings, $time, $this
- ));
- }
-
- if ($this->loggingQueries) {
- $this->queryLog[] = compact('query', 'bindings', 'time');
- }
- }
-
- /**
- * Register a database query listener with the connection.
- *
- * @param \Closure $callback
- * @return void
- */
- public function listen(Closure $callback)
- {
- if (isset($this->events)) {
- $this->events->listen(Events\QueryExecuted::class, $callback);
- }
- }
-
- /**
- * Fire an event for this connection.
- *
- * @param string $event
- * @return void
- */
- protected function fireConnectionEvent($event)
- {
- if (! isset($this->events)) {
- return;
- }
-
- switch ($event) {
- case 'beganTransaction':
- return $this->events->fire(new Events\TransactionBeginning($this));
- case 'committed':
- return $this->events->fire(new Events\TransactionCommitted($this));
- case 'rollingBack':
- return $this->events->fire(new Events\TransactionRolledBack($this));
- }
- }
实在不行了,还可以在事务上面想想办法,但是总归是只能一次处理,如果是需要两次执行sql。那还不如直接写代码呢。等有空再看了
PHP | 评论:0
| 阅读:17028