Skip to content

Instantly share code, notes, and snippets.

View blacklee's full-sized avatar

Black Lee blacklee

  • Hangzhou, China
View GitHub Profile
@blacklee
blacklee / gist:5733799
Created June 8, 2013 02:52
big files by find command.
sudo find / -size +200M -ls
sudo find / -size +200M -size -500M -ls
@blacklee
blacklee / remote server
Last active December 22, 2015 10:48
远程下载zip文件。远程机器网速快但存储不够。适用于中国用户下载国外资源。
cd /path/to/dir && wget -w 30 -i url-list.txt
# run by crond, */5 * * * * bash /path/to/dir/test.sh > /dev/null
cd /path/to/dir
for i in `ls *.zip`; do
unzip -t $i > /dev/null
if [[ $? -eq 0 ]]; then
mv $i download_done/
@blacklee
blacklee / gist:6505379
Created September 10, 2013 05:38
count file count in directory
# Files
find . -type f | wc -l
# Directories
find . -type d | wc -l
# Block special
find . -type b | wc -l
# Character special
@blacklee
blacklee / gist:6749499
Created September 29, 2013 05:00
stat command
# last modify time of file
stat -f "%m" $file
@blacklee
blacklee / application_controller.rb
Created October 11, 2013 03:10
Avoid user post a form to rails application repeated
class ApplicationController < ActionController::Base
before_filter :check_token, :only => [some_actions...]
def check_token
token_file = File.join(Rails.root.to_s, "tmp", "tokens", params[:__token__])
if File.exists?(token_file)
require 'fileutils'
FileUtils.rm(token_file)
return true
end
false
@blacklee
blacklee / gist:7781853
Last active December 30, 2015 05:19
UITableViewCell displays incorrectly before reusing.
UITableViewCell reuse problem.
appearance:
dynamic height cell, with dynamic UILabel...
the cell's height is calculated correctly, but the label shows wrong.
cell display incorrect before reuse, after reused, everything displays well.
in CostomCell's layoutSubviews method, each subview's frame is right if you print them.
reason:
App's using xib to draw custom UITableViewCell.
@blacklee
blacklee / gist:7782293
Created December 4, 2013 04:22
UITableView load content while scrolling
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
// somecode
[self performSelectorInBackground:@selector(loadMoreData:) withObject:nil];
}
- (void) loadMoreData:(id) s {
// some code to pull data from remote
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
@blacklee
blacklee / gist:8108962
Last active January 1, 2016 06:59
when layoutSubviews do not work
当 layoutSubviews 里设置了 frame 但是界面不刷新时,检查一下 xib 里面是不是勾上了 use Autolayout ,把这个去掉就好
When you have set frame in layoutSubviews but it do not refresh the view, we should uncheck the [use Autolayout] in xib.
@blacklee
blacklee / gist:8470154
Created January 17, 2014 08:34
git tag command
create:
git tag tagname
push to master:
git push --tags
list tags:
git tag --list
git tag -l
@blacklee
blacklee / MobClickOpenUDID+Swizzled.m
Created January 21, 2014 07:42
使用友盟统计分析提交时被拒的一种解决方案
#import "MobClickOpenUDID+Swizzled.h"
#import <objc/message.h>
#import <JRSwizzle.h> // Swizzle 类方法,这样可以避免类去调用某些Apple可能不允许的方法,通过审核
#import "YourDevice.h" // 你的设备相关类,用于生成自己的Device Unique ID
#import <RegExCategories.h> // 正则表达式
#import <NSString+Ruby.h> // 字符串工具类
static NSString * const kOpenUDIDKey = @"OpenUDID";
static NSString * const kOpenUDIDSlotKey = @"OpenUDID_slot";