Lydia's blog

Every day to be a little better


  • Home

  • Archives

  • Search

file not found: /usr/lib/system/libsystem_darwin.dylib for architecture x86_64

Posted on 2018-05-31 10:09

sudo xcode-select -s /Library/Developer/CommandLineTools

Untitled

Posted on 2018-05-31 10:00

title: ios-文件下载与分享
urlname: ios-file-download-and-share
date: 2017-12-22 09:50
updated: 2017-12-22 09:50
tags:

  • ios

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
30
31
32
33
34
35
36
37
38
39
-(void)download {
[SVProgressHUD showWithStatus:@"正在下载文件"];

NSURL *url = [NSURL URLWithString:self.currentRoute];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionTask *task = [session dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
//将下载后的数据存入文件(lastObject 无数据返回nil,不会导致程序崩溃)
_filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString* name = [_fileName stringByAppendingString:@".pdf"];
_filePath = [_filePath stringByAppendingPathComponent:name];
NSLog(@"%@",_filePath);

//将下载的二进制文件转成入文件
NSFileManager *manager = [NSFileManager defaultManager];
BOOL isDownLoad = [manager createFileAtPath:_filePath contents:data attributes:nil];
[Loading hide];
if (isDownLoad) {
[SVProgressHUD showSuccessWithStatus:@"下载完成"];
}else{
[SVProgressHUD showErrorWithStatus:@"下载失败,请重试"];
}
[SVProgressHUD dismissWithDelay:1];
}];
//开始下载 否则不会开始
[task resume];
}

-(void)sharePDF{
//创建实例(写成成员变量,不然可能导致分享出去被释放崩溃问题)
_documentController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:_filePath]];
//设置代理
_documentController.delegate = self;
BOOL canOpen = [_documentController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
if (!canOpen) {
NSLog(@"沒有程序可以打開要分享的文件");
[Loading showLoginFail:_webview for:@"沒有程序可以打開要分享的文件"];
[SVProgressHUD dismissWithDelay:1];
}
}
Read more »

css-bootstrap table-stripe reverse

Posted on 2018-05-28 15:00

.table-striped > tbody > tr:nth-of-type(odd) {
background: #fff !important;
}
.table-striped > tbody > tr:nth-of-type(even) {
background: #f9f9f9 !important;
}

ruby-position 排序

Posted on 2018-05-27 14:19

1.gem ‘acts_as_list’

2.model

1
acts_as_list

3.controller

1
2
3
4
5
6
7
8
9
10
11
up
@recruit_info.move_higher

down
@recruit_info.move_lower

top
@recruit_info.move_to_top

bottom
@recruit_info.move_to_bottom

4.view
一般置顶 最末会刷新页面
上移 下移用js

1
2
3
4
5
6
7
8
9
10
<%= link_to content_tag(:i, "", class: "fa fa-arrow-up"), "javascript:;", method: :post,
class: "info-up", data: { id: recruit_info.id, url: up_comp_recruit_info_path(recruit_info),
toggle: "popover", placement: "top", content: "上移" } %>
<%= link_to content_tag(:i, "", class: "fa fa-arrow-down"), "javascript:;", method: :post,
class: "info-down", data: { id: recruit_info.id, url: down_comp_recruit_info_path(recruit_info),
toggle: "popover", placement: "top", content: "下移" } %>
<%= link_to content_tag(:i, "", class: "fa fa-arrow-circle-up"), top_comp_recruit_info_path(recruit_info),
method: :post, class: "info-top", data: { toggle: "popover", placement: "top", content: "置顶" } %>
<%= link_to content_tag(:i, "", class: "fa fa-arrow-circle-down"), bottom_comp_recruit_info_path(recruit_info),
method: :post, class: "info-bottom", data: { toggle: "popover", placement: "top", content: "最末" } %> |
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<script type="text/javascript">

$prevLink = $('.pagination').find('.active').prev().find('a').attr('href');
$nextLink = $('.pagination').find('.active').next().find('a').attr('href');

$('.info-up').on('click', function(){
const pageFirst = $('.recruit-info-item').first();
$page = $(this).closest('.recruit-info-item');
$.ajax({
url: $(this).data('url'),
type: 'POST',
data: {
id: $(this).data('id')
},
success: function() {
if ($page.is(pageFirst)) {
if (<%= @recruit_infos.current_page %> === 1) {
$.notify('不可上移!!','error')
} else {
window.location.href = $prevLink
}
} else {
$page.prev().before($page);
}
}
});
});

$('.info-down').on('click', function(){
const pageLast = $('.recruit-info-item').last();
$page = $(this).closest('.recruit-info-item');
$.ajax({
url: $(this).data('url'),
type: 'POST',
data: {
id: $(this).data('id')
},
success: function() {
if ($page.is(pageLast)) {
if (<%= @recruit_infos.total_pages == @recruit_infos.current_page %>) {
$.notify('不可下移!!','error')
} else {
window.location.href = $nextLink
}
} else {
$page.next().after($page);
}
}
});
});
</script>

ps: 必须有position字段如果是后加的 在migration文件中需要

1
2
3
ExampleCv.order(updated_at: :desc).each.with_index(1) do |todo_item, index|
todo_item.update_column :position, index
end

微信小程序-获取小程序二维码

Posted on 2018-05-25 17:34
def miniProgramQR
 res = RestClient.get 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='+ ENV['WECHAT_MINIPROGRAM_APP_ID'] + '&secret=' + ENV['WECHAT_MINIPROGRAM_APP_SECRECT']
  json = JSON.parse res.body
  access_token = json['access_token']
  miniProgram_image = RestClient.post 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=' + access_token, {'page': 'pages/cvShare/cvShare', 'scene': @cv.token}.to_json, {content_type: :json, accept: :json}
  image = Base64.encode64 miniProgram_image
 render json: {
    image: image
  }
end

ps: scene 最大32位 可以用’type:’ + params[:file_type] +’,id:’ + params[:token]这种字符串 然后在小程序中用js分割,不可以用json格式、也不可以用to_s

显示用$(‘.qr-code’).attr(‘src’, “data:image/jpeg;base64,” + data[‘image’])

ruby-ascii-8bit 转image

Posted on 2018-05-25 11:33

1.将data转成base64编码 用Base64.encode64 data

2.用data_uri的方法 将base64编码展示出来

“data:image/jpeg;base64,data”

data uri scheme

js-data传参键名是变量不能识别

Posted on 2018-05-23 16:16

const fileData= {};
fileData[fileType] = data;

ps: 一定要注意 在里面写的时候data: fileData 这么传值!

js-判断页面是否加载完成

Posted on 2018-05-22 17:12

对于页面来说,dom结构,样式,脚本也属于内容,页面内的图片文字视频音频也是内容。

那么我们常用的 window.onload和 jquery 中的 ready 函数就能判断内容是否全部加载完成吗?答案是否定的。以上两个只能判定页面骨架加载完成了,但是不能判定页面资源是否加载完成,比如页面的超大图片,视频等。还有如果是有异步请求的资源等都无法检测到的,尤其是在 onload 之后发生的请求。

onreadystatechange回调不行,原因:每当有请求发生时 readyState 都会改变并触发 onreadystatechange

如果需要动态处理 dom 那么在 onload|ready 中就可以了,因为此时页面 dom 已经加载完成了。如果你需要对某些异步的请求做监控,则只需要在对应的异步中添加上回调即可。

1
2
3
4
5
6
7
if(document.readyState == “complete”) //当页面加载状态 



window.onload页面(包括资源)准备就绪

document.onloadDOM加载完毕

微信小程序-iphonx适配

Posted on 2018-05-22 11:17

在app.js文件中 创建全局变量,然后获取设备型号

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
globalData: {  
isIphoneX: false,
userInfo: null
},
onShow:function(){
let that = this;
wx.getSystemInfo({
success: res=>{
// console.log('手机信息res'+res.model)
let modelmes = res.model;
if (modelmes.search('iPhone X') != -1) {
that.globalData.isIphoneX = true
}

}
})

},

在需要引用的页面js文件中onload方法里获取全局变量

1
2
3
4
let isIphoneX = app.globalData.isIphoneX;
this.setData({
isIphoneX: isIphoneX
})

ps:button 的边框用button::after{ border: none; }来去除

redis-数据缓存

Posted on 2018-05-17 11:12

gem ‘redis-namespace’
bundle
新建文件 config/initializers/redis.rb

1
$redis = Redis::Namespace.new("site_point", :redis => Redis.new)

存 $redis.set(“test_key”, “Hello World!”)
取 $redis.get(“test_key”)
删 $redis.del “categories”

参考

1…121314…28

Lydia

This is lydia's blog

277 posts
1 categories
46 tags
© 2020 Lydia
Powered by Hexo
|
Theme — NexT.Muse v5.1.4