简单想法

用于记录一些简短的想法

Views: 99223

446 Responses to "简单想法"

  • Cocoa View 另存为图片:


    [view lockFocus];
    NSRect bounds = [view bounds];
    NSBitmapImageRep* rep;
    rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:bounds];
    [view unlockFocus];

    // 或者
    BitmapImageRep* rep = [view bitmapImageRepForCachingDisplayInRect:self.bounds];
    [view cacheDisplayInRect:self.bounds toBitmapImageRep:rep];

    NSData *data = [rep representationUsingType:NSJPEGFileType properties:nil];
    [data writeToFile:@"/path/to/file.jpg" atomically:NO];
    Reply
  • git 修改 commit log:


    git commit --amend
    Reply

  • valgrind --tool=memcheck --leak-check=yes --show-reachable=yes ./myapp

    Reply
  • Cocoa Webview 获取当前鼠标下的 DOM 节点:

    NSPoint point = [theEvent locationInWindow];
    NSDictionary *dict = [webView elementAtPoint:point];
    DOMNode *node = [dict objectForKey:@"WebElementDOMNode"];
    Reply
  • Mac OSX 下复制应用程序的 logo:

    1. 在 Finder 中找到应用程序(*.app)
    2. Cmd + C 复制
    3. 启动 Preview
    4. 选择菜单 File -> New From Clipboard Reply
  • [NSImage imageNamed:@"NSApplicationIcon"]; Reply
  • TCP socket 默认并没有启用 keepalive, 需要启用:


    int opt = 1;
    ::setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&opt, sizeof(opt));


    同时, 还要修改操作系统的相关配置:


    # echo 600 > /proc/sys/net/ipv4/tcp_keepalive_time
    # echo 60 > /proc/sys/net/ipv4/tcp_keepalive_intvl
    # echo 5 > /proc/sys/net/ipv4/tcp_keepalive_probes
    Reply
  • strace -p 12345 Reply
  • 命令行编译 Objective-C 代码:

    clang -lobjc -fobjc-arc -framework Foundation test.m Reply
  • vim 粘贴时禁用自动格式化的方法:
    :set paste
    ctrl+v
    :set nopaste Reply

« [2][3][4][5][6][7][8][9][10] » 6/45