Skip to content

Instantly share code, notes, and snippets.

View shuizhongyueming's full-sized avatar
🎯
Focusing

happy wang shuizhongyueming

🎯
Focusing
View GitHub Profile
@shuizhongyueming
shuizhongyueming / pfv.js
Created April 16, 2023 11:29
analytics execution time for code block
/**
# Usages:
pfv.start('some');
// some code
// some code
pfv.end();
pfv.check('ff', () => {
// some code
@shuizhongyueming
shuizhongyueming / javascript-for-statement
Last active December 17, 2018 04:49
simple achievement of javascript for statement
function forFunc(curr, compare, changer, actions) {
if (compare(curr)) {
actions(curr);
return forFunc(changer(curr), compare, changer, actions);
}
}
function iterateArr(arr, actions) {
forFunc(0, i => i < arr.length, i => i+1, i => actions(arr[i], i));
}
@shuizhongyueming
shuizhongyueming / datasource-tasks-results
Created November 23, 2015 11:27 — forked from serkanserttop/datasource-tasks-results
Loopback Model Discovery, bug?
//DataSource.prototype.discoverSchemas
//async.parallel(tasks, function (err, results) {
// console.log(results);
//https://github.com/strongloop/loopback-datasource-juggler/blob/master/lib/datasource.js#L1205
[
[
{ owner: 'chosendb',
tableName: 'chosentable',
columnName: 'id'
},
@shuizhongyueming
shuizhongyueming / md5.m
Created May 16, 2014 03:09
实现md5加密的方案
-(NSString *)md5:(NSString *)str {
//转换成utf-8
const char *cStr = [str UTF8String];
//开辟一个16字节(128位:md5加密出来就是128位/bit)的空间(一个字节=8字位=8个二进制数)
unsigned char result[16];
CC_MD5( cStr, strlen(cStr), result);
@shuizhongyueming
shuizhongyueming / reuseTableViewCell.m
Created April 23, 2014 09:12
cellForRowAtIndex时,使用到的可重用的cell
SomeCell * cell = [tableView dequeueReusableCellWithIdentifier:@"someIdentifier"];
if(cell == nil){
cell = [[SomeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"someIdentifier"];
}
@shuizhongyueming
shuizhongyueming / UIButton+Stretchable.m
Created April 7, 2014 08:59
一个通用的给UIButton的background的图片做拉伸的委托
@implementation UIButton (StretchableUIButton)
/* Automatically set cap insets for the background image. This assumes that
the image is a standard slice size with a 1 px stretchable interior */
- (void)setBackgroundImageStretchableForState:(UIControlState)controlState
{
UIImage *image = [self backgroundImageForState:controlState];
if (image)
{
CGFloat capWidth = floorf(image.size.width / 2);
CGFloat capHeight = floorf(image.size.height / 2);
@shuizhongyueming
shuizhongyueming / UIActionSheet.m
Created February 18, 2014 09:05
如何使用UIActionSheet
// 定义一个UIActionSheet
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"Are you sure?"
delegate:self
cancelButtonTitle:@"No Way!"
destructiveButtonTitle:@"Yes, I'm Sure"
// 其他按钮,没有直接写nil
otherButtonTitles:@"Foo",@"Bar",nil];
// 放到View中显示
@shuizhongyueming
shuizhongyueming / fixedInIe6.css
Created September 9, 2013 11:53
修复IE6不支持fixed的问题,用css表达式来实现
/*让position:fixed在IE6下可用! */
 
.fixed-top /* 头部固定 */{position:fixed;bottom:auto;top:0px;}
.fixed-bottom /* 底部固定 */{position:fixed;bottom:0px;top:auto;}
.fixed-left /* 左侧固定 */{position:fixed;right:auto;left:0px;}
.fixed-right /* 右侧固定 */{position:fixed;right:0px;left:auto;}
/* 上面的是除了IE6的主流浏览器通用的方法 */
* html,* html body /* 修正IE6振动bug */{background-image:url(about:blank);background-attachment:fixed;}
* html .fixed-top /* IE6 头部固定 */{position:absolute;bottom:auto;top:expression(eval(document.documentElement.scrollTop));}
* html .fixed-right /* IE6 右侧固定 */ {position:absolute;right:auto;left:expression(eval(document.documentElement.scrollLeft+document.documentElement.clientWidth-this.offsetWidth)-(parseInt(this.currentStyle.marginLeft,10)||0)-(parseInt(this.currentStyle.marginRight,10)||0));}
@shuizhongyueming
shuizhongyueming / FlashSatay.html
Created August 27, 2013 05:00
From http://alistapart.com/article/flashsatay 一个比较通用的在页面中加载flash的方式,用的是object标签。但是考虑到现在html5的日渐普及,这种方式在日后的可用性还是有待商榷
<object type="application/x-shockwave-flash"
data="c.swf?path=movie.swf"
width="400" height="300">
</object>
@shuizhongyueming
shuizhongyueming / checkMail.js
Created May 10, 2013 17:25
JavaScript: Util checkMail
/**
* [checkMail 验证用户输入的邮箱格式是否正确]
* @param {[string]} mailStr [已经去除两边空白的邮箱地址]
* @return {[int]} [0,合法;1,不合法]
*/
function checkMail(mailStr){//验证邮箱格式
if(mailStr.match(/^[\w-]+@[\w-]+((\.[\w-]{2,3}){1,2})$/gi)){return 0;}
else{return 1;}
}