Peterfei

上主是我的牧者,我实在一无所缺


  • 首页

  • 归档

  • 标签

Ionic 更新默认图标

发表于 2015-11-04   |   分类于 Ionic   |  

项目中要替换ionic 默认的icon 图标,Google 一下,大多是让图标生成svg的格式,下面有一种比较容易的方式去实现:

e.g. 在浏览器的调试模式,选中需要替换的图标,找到如下代码:

1
2
3
.ion-ios-home-outline:before {
content: "\f447";
}

在/img/找出要替换的icon图,如car.png
在样式表里写入如下代码:

1
2
3
4
.ion-ios-home-outline:before {
/*content: "\f447";*/
content: url('../img/car.png') !important;
}

效果图

puma 在nginx 启动后报错解决

发表于 2015-10-31   |   分类于 ROR   |  

##在Centos上部署时遇到如下错误:

puma nginx connect() Permission denied

解决方法:在nginx.conf 配置文件中加入了puma 用户:
user deploy

puma 启动时的用户,如此启动正常。

Sublime 中自定义snippets

发表于 2015-10-29   |   分类于 工具   |  

##选择tool->new snippet
内容如下:

1
2
3
4
5
6
7
8
9
<snippet>
<content><![CDATA[
Hello, ${1:this} is a ${2:snippet}.
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>hello</tabTrigger> -->
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>

  1. Hello, ${1:this} is a ${2:snippet} 这正是你要插入到文档中的文本。在此节放入的任何片段都会被插入到你的文档中。
  2. tabTrigger 此节是可选的配置,默认是被注释掉的。默认 hello 的意思是:如果你在某个文档里输入了单词 hello ,然后按下 Tab 键,接着 hello 就会被替换为1中定义的代码片段。再次按下Tab键,接着snippet会被替换为2中定义的代码片段
  3. scope 此节也是可选配置,默认是被注释掉的。默认 source.php 的意思是:只有在编辑 php 源码的时候,才能用此代码片段

##保存代码片段文件
在能自定义代码片段之前,应该首先保存。在保存文件对话框里,需要明确的指定文件的扩展名为.sublime-snippet,然后把文件保存到默认目录(当前用户主目录下的\Sublime Text 3\Packages\User目录中)。

保存文件之后,就可以测试上面提到的tabTrigger功能了。如果不再使用此功能,可以在此注释掉.

##修改代码片段文件
在创建新代码片段中提到过 Hello, ${1:this} is a ${2:snippet} ,其中 ${1:this} 和 ${2:snippet} 是占位符。在插入代码片段后,单词 this 被选中,如果键入内容,this 将会被替换掉,接着按下 Tab 键,将会选中单词 snippet,如果键入内容,snippet 将会被替换掉。

##绑定快捷键

可以将上述的操作绑定到一个快捷键,在不键入任何文本的情况下,直接按快捷键插入代码片段。

点击菜单栏的 Preferences 的子菜单 Key Binding – User,在打开的文件的方括号内部粘贴如下配置:

1
{ “keys”: [“ctrl+1″], “command”: “insert_snippet”, “args”: {“name”: “Packages/User/example.sublime-snippet”} }

现在简单介绍一下这段配置:

  1. “keys”: [“ctrl+1″] 这个定义了触发此命令的快捷键。

  2. “command”: “insert_snippet” 这个是需要触发的命令的名字。

  3. “args”: {“name”: “Packages/User/example.sublime-snippet”} 这个是需要传入到上述命令的参数。这里把代码片段文件的相对路径传递过去。

保存配置文件,现在就可以用快捷键插入代码片段了。

以下是我Ruby的注释代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<snippet>
<content><![CDATA[
# ########################################################
# | Software: ${1}
# | Version: 2015.10
# | Site: http://peterfei.me
# |--------------------------------------------------------
# | Author: peterfei <peterfeispace@gmail.com>
# | Copyright (c) 2012-2015, http://peterfei.me. All Rights
#Reserved.
# | Time: ${2}
# ########################################################
${3}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>hello</tabTrigger> -->
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>

因为上例中有写Time 获取当前时间的,于是写个获取当前时间的:

创建插件:Tools → New Plugin:

1
2
3
4
5
6
7
8
9
import datetime
import sublime_plugin
class AddCurrentTimeCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.run_command("insert_snippet",
{
"contents": "%s" % datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
}
)

保存为Sublime Text 2\Packages\User\addCurrentTime.py

创建快捷键:Preference → Key Bindings - User:

1
2
3
4
5
6
7
8
[
{
"command": "add_current_time",
"keys": [
"ctrl+shift+."
]
}
]

此时使用快捷键ctrl+shift+.即可在当前光标处插入当前时间,如下:

1
2
3
4
5
6
7
8
9
10
# ########################################################
# | Software: test
# | Version: 2015.10
# | Site: http://peterfei.me
# |--------------------------------------------------------
# | Author: peterfei <peterfeispace@gmail.com>
# | Copyright (c) 2012-2015, http://peterfei.me. All Rights
#Reserved.
# | Time: 2015-10-29 09:58:53
# ########################################################

angularjs mobiscroll 日期用例

发表于 2015-10-27   |   分类于 前端   |  

Angularjs 写了个mobiscroll directive :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
.directive('mobiDateTimePicker', function() {
return {
restrict: 'A',
link: function($scope, element, attrs) {
return $(element).mobiscroll().datetime({
theme: 'default',
display: 'bottom',
lang:'zh',
minWidth:40,
steps:{ minute: 15},
rows:3,
// dayText: '日', monthText: '月', yearText: '年',
dateFormat: 'yy-MM-dd',
timeFormat: 'HH:ii:ss',
// timeWheels: 'HHii',
showNow: true,
showLabel:true,
dateOrder: 'yyyyMMddDD',
// tap:true,
// invalid:[{'10/27',start:'18:00',end:"19:00"}]
headerText: function (valueText) { //自定义弹出框头部格式
return valueText;
},
// dayNames:['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
});
}
};
})

其中:minWidth:40是控件的显示高度,dateOrder: 'yyyyMMddDD',可显示友好的星期+日期:

Angularjs 判断服务器401错误

发表于 2015-10-21   |   分类于 前端   |  

之前在github上有篇判断augularjs401状态码的:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
var logsOutUserOn401 = function($location, $q, SessionService, FlashService) {
var success = function(response) {
return response;
};
var error = function(response) {
if(response.status === 401) {
SessionService.unset('authenticated');
$location.path('/login');
FlashService.show(response.data.flash);
}
return $q.reject(response);
};
return function(promise) {
return promise.then(success, error);
};
};
$httpProvider.responseInterceptors.push(logsOutUserOn401);

今天用时才发现$httpProvider.responseInterceptors方法已经被官方弃用了。
改写了方案如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
app.factory('errorInterceptor', ['$q', '$rootScope', '$location','FlashService',
function ($q, $rootScope, $location,FlashService) {
return {
request: function (config) {
return config || $q.when(config);
},
requestError: function(request){
return $q.reject(request);
},
response: function (response) {
return response || $q.when(response);
},
responseError: function (response) {
if(response.status === 401) {
// SessionService.unset('authenticated');
FlashService.show(response.data.error);
$location.path('/login');
}
if (response && response.status === 404) {
}
if (response && response.status >= 500) {
}
return $q.reject(response);
}
};
}]);

在app.js config 方法调用时:

1
$httpProvider.interceptors.push('errorInterceptor');

1…101112…16
peterfei

peterfei

peterfei|技术|上主是我的牧者

79 日志
14 分类
62 标签
RSS
github
© 2025 peterfei
由 Hexo 强力驱动
主题 - NexT.Mist