小编So *_* It的帖子

如何在PHP中创建唯一的用户指纹

在PHP中生成用户唯一性的"指纹"的最佳方法是什么?

例如:

  1. 我可以使用用户的IP地址作为"指纹",但是,同一IP上可能有多个其他用户
  2. 我可以使用用户的IP +用户代理作为"指纹",但是,单个用户可以简单地从safari交换到firefox并再次被视为唯一

理想情况下,指纹标记"机器"而不是浏览器或"ip",但我想不出这是如何实现的.

随时了解您如何唯一识别用户的想法/建议,以及您的方法有哪些优点/缺点.

php statistics user-agent identifier fingerprint

24
推荐指数
3
解决办法
4万
查看次数

为代表提供"强大"的参考资料是否真的好?

我有一个类从URL检索JSON并通过协议/委托模式返回数据.

MRDelegateClass.h

#import <Foundation/Foundation.h>

@protocol MRDelegateClassProtocol
@optional
- (void)dataRetrieved:(NSDictionary *)json;
- (void)dataFailed:(NSError *)error;
@end

@interface MRDelegateClass : NSObject
@property (strong) id <MRDelegateClassProtocol> delegate;

- (void)getJSONData;
@end
Run Code Online (Sandbox Code Playgroud)

请注意,我正在使用strong我的委托属性.以后更多关于......

我正在尝试编写一个"包装"类,它以基于块的格式实现getJSONData.

MRBlockWrapperClassForDelegate.h

#import <Foundation/Foundation.h>

typedef void(^SuccessBlock)(NSDictionary *json);
typedef void(^ErrorBlock)(NSError *error);

@interface MRBlockWrapperClassForDelegate : NSObject
+ (void)getJSONWithSuccess:(SuccessBlock)success orError:(ErrorBlock)error;
@end
Run Code Online (Sandbox Code Playgroud)

MRBlockWrapperClassForDelegate.m

#import "MRBlockWrapperClassForDelegate.h"
#import "MRDelegateClass.h"

@interface DelegateBlock:NSObject <MRDelegateClassProtocol>
@property (nonatomic, copy) SuccessBlock successBlock;
@property (nonatomic, copy) ErrorBlock errorBlock;
@end

@implementation DelegateBlock
- (id)initWithSuccessBlock:(SuccessBlock)aSuccessBlock andErrorBlock:(ErrorBlock)aErrorBlock {
    self = [super init];
    if (self) {
        _successBlock …
Run Code Online (Sandbox Code Playgroud)

delegates memory-management objective-c objective-c-blocks automatic-ref-counting

19
推荐指数
3
解决办法
9388
查看次数

如何在initWithCoder中通过storyboard添加自定义UIView的维度:?

我有一个自定义的UIView子类,它在初始化过程中以编程方式添加子视图.我希望这个子视图与自定义UIView的宽度相同.

如果我以编程方式添加自定义UIView,我的代码工作正常.但是,当通过StoryBoard初始化UIView时,我无法获得自定义UIView的宽度.

// Init programatically
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        NSLog (@"view: %f", self.frame.size.width);   //WILL return width
        NSLog (@"view: %f", self.bounds.size.width);  //WILL return width
    }
    return self;
}

// Init from storyboard
- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {

        NSLog (@"view: %f", self.frame.size.width);   //Returns 0
        NSLog (@"view: %f", self.bounds.size.width);  //Returns 0
    }
    return self;
}
Run Code Online (Sandbox Code Playgroud)

当initWithCoder:由StoryBoard运行时,UIView的框架和边界都返回为0.有没有办法 initWithCoder 中访问UIView的尺寸?或者,至少调用drawRect:之前访问维度?

谢谢.

objective-c uiview uistoryboard

15
推荐指数
1
解决办法
6579
查看次数

使用NSPredicate基于多个键进行过滤(键的NOT值)

我有以下包含NSDictionary的NSArray:

NSArray *data = [[NSArray alloc] initWithObjects:
                 [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:1], @"bill", [NSNumber numberWithInt:2], @"joe", nil],
                 [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:3], @"bill", [NSNumber numberWithInt:4], @"joe", [NSNumber numberWithInt:5], @"jenny", nil],
                 [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:6], @"joe", [NSNumber numberWithInt:1], @"jenny", nil],
                 nil];
Run Code Online (Sandbox Code Playgroud)

我想创建一个过滤的NSArray,它只包含NSDictionary使用NSPredicate匹配多个"键"的对象.

例如:

  • 过滤数组只包含具有键"bill"和"joe"的NSDictionary对象[所需结果:新的NSArray将包含两个NSDictionary对象]
  • 过滤数组只包含具有键"joe"和"jenny"的NSDictionary对象[所需结果:新的NSArray将包含最后两个NSDictionary对象]

任何人都可以解释NSPredicate的格式来实现这一目标吗?

编辑:我可以使用以下方法获得与所需NSPredicate类似的结果:

NSMutableArray *filteredSet = [[NSMutableArray alloc] initWithCapacity:[data count]];
NSString *keySearch1 = [NSString stringWithString:@"bill"];
NSString *keySearch2 = [NSString stringWithString:@"joe"];

for (NSDictionary *currentDict in data){
    // objectForKey will return nil if a key doesn't exists.
    if ([currentDict objectForKey:keySearch1] …
Run Code Online (Sandbox Code Playgroud)

cocoa objective-c nsarray nspredicate

10
推荐指数
2
解决办法
1万
查看次数

如何将SKNode渲染为UIImage

只是玩SpriteKit,我试图弄清楚如何捕获SKNode的'抓取'到UIImage.

使用UIView(或UIView子类),我使用layer视图的属性渲染到图形上下文中.

例如.

#import <QuartzCore/QuartzCore.h>
+ (UIImage *)imageOfView:(UIView *)view {
    UIGraphicsBeginImageContextWithOptions(view.frame.size, YES, 0.0f);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [view.layer renderInContext:context];
    UIImage *viewShot = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return viewShot;
}
Run Code Online (Sandbox Code Playgroud)

SKNode不是UIView的子类,因此似乎没有图层支持.

关于如何将给定的SKNode呈现给UIImage的任何想法?

objective-c uiimage ios sprite-kit sknode

10
推荐指数
2
解决办法
3633
查看次数

NSPredicate'OR'过滤基于NSArray键

考虑以下NSArray:

NSArray *dataSet = [[NSArray alloc] initWithObjects:
                 [NSDictionary dictionaryWithObjectsAndKeys:@"abc", @"key1", @"def", @"key2", @"hij", @"key3", nil], 
                 [NSDictionary dictionaryWithObjectsAndKeys:@"klm", @"key1", @"nop", @"key2", nil], 
                 [NSDictionary dictionaryWithObjectsAndKeys:@"qrs", @"key2", @"tuv", @"key4", nil], 
                 [NSDictionary dictionaryWithObjectsAndKeys:@"wxy", @"key3", nil], 
                 nil];
Run Code Online (Sandbox Code Playgroud)

我能够过滤此数组以查找包含密钥的字典对象 key1

// Filter our dataSet to only contain dictionary objects with a key of 'key1'
NSString *key = @"key1";
NSPredicate *key1Predicate = [NSPredicate predicateWithFormat:@"%@ IN self.@allKeys", key];
NSArray *filteretSet1 = [dataSet filteredArrayUsingPredicate:key1Predicate];
NSLog(@"filteretSet1: %@",filteretSet1);
Run Code Online (Sandbox Code Playgroud)

适当回报:

filteretSet1: (
        {
        key1 = abc;
        key2 = def;
        key3 …
Run Code Online (Sandbox Code Playgroud)

objective-c foundation nsarray nspredicate

8
推荐指数
1
解决办法
4714
查看次数

如何可靠地确定UICollectionView布局何时完成动画

我在找出确定UICollectionView何时完成动画的方法时遇到了问题.

我目前有一个UICollectionView,它使用两个子类流程布局之间的动画 setCollectionViewLayout:animated:

动画看起来很棒,但是,如果用户动画期间选择了一个单元格,我会遇到一些不良行为.

我期待在忽略细胞"选择"通过返回NO通过UICollectionViewDelegate方法collectionView:shouldSelectItemAtIndexPath:-然而-我想不出一个可靠的测试,以查看是否集合视图当前动画.

有任何想法吗?

objective-c uicollectionview

7
推荐指数
1
解决办法
986
查看次数

MySQL - 如何优化查询以计算投票数

在听取了关于实现以下结果的最佳方法的一些意见之后:

我想在我的MySQL数据库中存储可以由用户投票的产品(每个投票值+1).我还希望能够看到用户投票的总次数.

简单来说,下表结构是理想的:

  table: product          table: user            table: user_product_vote       
+----+-------------+    +----+-------------+    +----+------------+---------+ 
| id |   product   |    | id | username    |    | id | product_id | user_id |
+----+-------------+    +----+-------------+    +----+------------+---------+
| 1  | bananas     |    | 1  | matthew     |    | 1  | 1          | 2       |
| 2  | apples      |    | 2  | mark        |    | 2  | 2          | 2       |
| .. | ..          |    | .. | ..          |    | .. | .. …
Run Code Online (Sandbox Code Playgroud)

mysql query-optimization

6
推荐指数
1
解决办法
1829
查看次数

从iOS5中的TableView将数据传递到DetailViewController时出现问题

我很感激任何帮助解决我的问题让我在最后一天拔头发!

免责声明1 我是一个Objective-C菜鸟 - 所以答案可能非常简单(我来自多年的PHP).请友好一点.

免责声明2 是的,我已经广泛"谷歌搜索"并查看了Apple文档 - 但未能理解我的问题.

摘要

我试图将表视图中选择的值从单例传递给另一个控制器.我发现第二个视图控制器中的viewDidLoad方法在tableView:didSelectRowAtIndexPath:方法之前完成,该方法触发了segue.这导致第二个视图控制器访问"陈旧"数据.

详情

我使用针对iOS5的ARC设置了一个非常简单的StoryBoard项目.

故事板

我创建了一个单例来在视图控制器之间存储NSString.

Singleton.h

#import <Foundation/Foundation.h>
@interface Singleton : NSObject
@property (strong, nonatomic) NSString *sharedString;
+ (id)singletonManager;
@end
Run Code Online (Sandbox Code Playgroud)

Singleton.m

#import "Singleton.h"

static Singleton *sharedInstance = nil;

    @implementation Singleton
    @synthesize sharedString = _sharedString;
    +(id)singletonManager
    {
        @synchronized(self){
            if (sharedInstance == nil)
                sharedInstance = [[self alloc] init];
        }
        return sharedInstance;
    }
    -(id) init {
        if (self = [super init]) {
            _sharedString = [[NSString alloc] initWithString:@"Initialization String"];
        }
        return …
Run Code Online (Sandbox Code Playgroud)

singleton objective-c uitableview ios segue

4
推荐指数
1
解决办法
2503
查看次数

自从更新到Swift 1.2以来,Dictionary现在给出错误'不能转换为BooleanLiteralConvertible'

我只是围绕Swift - 然后来了Swift 1.2(打破我的工作代码)!

我有一个基于NSHipster的代码示例的函数 - CGImageSourceCreateThumbnailAtIndex.

我以前工作的代码是:

import ImageIO

func processImage(jpgImagePath: String, thumbSize: CGSize) {

    if let path = NSBundle.mainBundle().pathForResource(jpgImagePath, ofType: "") {
        if let imageURL = NSURL(fileURLWithPath: path) {
            if let imageSource = CGImageSourceCreateWithURL(imageURL, nil) {

                let maxSize = max(thumbSize.width, thumbSize.height) / 2.0

                let options = [
                    kCGImageSourceThumbnailMaxPixelSize: maxSize,
                    kCGImageSourceCreateThumbnailFromImageIfAbsent: true
                ]

                let scaledImage = UIImage(CGImage: CGImageSourceCreateThumbnailAtIndex(imageSource, 0, options))

                // do other stuff
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

从Swift 1.2开始,编译器提供了两个与options字典相关的错误:

  1. 如果没有更多的上下文,表达的类型是不明确的
  2. '_'不能转换为'BooleanLiteralConvertible' (在ref为'true'值时) …

dictionary cgimage swift

4
推荐指数
1
解决办法
1426
查看次数

Javascript ES6:如何从超类中定义的静态方法中检索调用子类

JavaScript新手.

寻求关于如何使用ES6类从超类中定义的静态方法访问调用类名的一些指导.我花了一个小时搜索,但一直没能找到解决方案.

代码片段可能有助于澄清我在寻找什么

class SuperClass {
    get callingInstanceType() { return this.constructor.name }
    static get callingClassType() { return '....help here ...' }
}

class SubClass extends SuperClass { }

let sc = new SubClass()

console.log(sc.callingInstanceType)     // correctly prints 'SubClass'
console.log(SubClass.callingClassType)  // hoping to print 'SubClass'
Run Code Online (Sandbox Code Playgroud)

如上所示,我可以轻松地从实例中获取子类名称.不太确定如何从静态方法访问.

static get callingClassType()欢迎实施的想法.

javascript es6-class

3
推荐指数
1
解决办法
1106
查看次数

有没有更优雅的方法在NSArray中找到唯一的NSDictionary键?

目标:使用优雅代码获取包含给定NSDictionary的唯一键的NSArray

带当前工作解决方案的示例代码

NSArray *data = [[NSArray alloc] initWithObjects:
                 [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:1], @"a", [NSNumber numberWithInt:2], @"b", nil],
                 [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:3], @"b", [NSNumber numberWithInt:4], @"c", nil],
                 [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:5], @"a", [NSNumber numberWithInt:6], @"c", nil],
                 [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:7], @"b", [NSNumber numberWithInt:8], @"a", nil],
                 [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:8], @"c", [NSNumber numberWithInt:9], @"b", nil],
                 nil];

// create an NSArray of all the dictionary keys within the NSArray *data
NSMutableSet *setKeys = [[NSMutableSet alloc] init]; 
for (int i=0; i<[data count]; i++) {
    [setKeys addObjectsFromArray:[[data objectAtIndex:i] allKeys]]; …
Run Code Online (Sandbox Code Playgroud)

objective-c nsdictionary nsarray kvc

0
推荐指数
1
解决办法
1254
查看次数