Skip to content

Instantly share code, notes, and snippets.

@zrxq
zrxq / uuid1.py
Created June 30, 2011 08:11
Sublime Text 2 plugin for inserting UUID 1 (host- and time-based)
import sublime, sublime_plugin
from uuid import uuid1
class generate_uuid1Command(sublime_plugin.TextCommand):
def insert_text(self, edit, what):
[self.view.replace(edit, reg, what) for reg in self.view.sel()]
def run(self, edit):
self.insert_text(edit, str(uuid1()))
@zrxq
zrxq / DetectFaces.cs
Created July 30, 2011 13:22
Face detection in C# using OpenCV with P/Invoke
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace OpenCVFaceDetector
{
class DllPaths
@zrxq
zrxq / Python.sublime-build
Created November 15, 2011 09:52
Sublime Text python build system which respects environment variables set in ~/.profile (e.g. $PYTHONPATH)
{
"cmd": ["bash", "--login", "-c", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
@zrxq
zrxq / unshred.py
Created February 10, 2012 10:17
The Unshredder (Instagram Engineering Challenge)
#!/usr/bin/python
# This script unshreds a shredded image (visit http://bit.ly/sCMAD5 for details)
# author: Zoreslav Khimich <zoreslav.khimich@gmail.com>
from PIL import Image, ImageChops, ImageStat
from argparse import ArgumentParser
import sys, heapq
MAGIC_THRESHOLD = 11 # carefully handpicked to work with your reference input
@zrxq
zrxq / ZKCGHelpers.c
Created May 9, 2012 09:34
Left side rounded and right side rounded rectangles using Quartz 2D
//
// ZKCGHelpers.c
// Quartz 2D Helpers
//
// Created by Zoreslav Khimich on 5/9/12.
// Copyright (c) 2012 Zoreslav Khimich. All rights reserved.
//
#include "ZKCGHelpers.h"
@zrxq
zrxq / UIViewController+ZWDModalOverlay.h
Created February 2, 2013 05:10
Modal overlay views with orientation support
//
// UIViewController+ZWDModalOverlay.h
//
// Created by Zoreslav Khimich on 28/01/2013.
// Copyright (c) 2013 zrxq. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIViewController (ZWDModalOverlay)
@zrxq
zrxq / gist:5362898
Last active December 16, 2015 02:29
contentCenter CGRect for a CALayer from a resizable UIImage (resizableImageWithCapInsets)
inline static CGRect CGRectCenterRectForResizableImage(UIImage *image) {
return CGRectMake(image.capInsets.left/image.size.width, image.capInsets.top/image.size.height, (image.size.width-image.capInsets.right-image.capInsets.left)/image.size.width, (image.size.height-image.capInsets.bottom-image.capInsets.top)/image.size.height);
}
@zrxq
zrxq / gist:5363610
Last active February 3, 2016 15:35
CGRect inset with UIEdgeInsets
inline static CGRect CGRectEdgeInset(CGRect rect, UIEdgeInsets insets) {
return CGRectMake(CGRectGetMinX(rect)+insets.left, CGRectGetMinY(rect)+insets.top, CGRectGetWidth(rect)-insets.left-insets.right, CGRectGetHeight(rect)-insets.top-insets.bottom);
}
@zrxq
zrxq / DatePickingCell.h
Created May 29, 2013 13:37
UITableViewCell + UIDatePicker
#import <UIKit/UIKit.h>
@interface DatePickingCell : UITableViewCell
@property (strong, nonatomic) UIDatePicker *datePicker;
@end
@zrxq
zrxq / objc-run.sublime-build
Created January 12, 2014 15:38
Sublime text build system for Objective-C files (via objc-run, see https://github.com/iljaiwas/objc-run)
{
"cmd": ["/usr/local/bin/objc-run", "$file"],
}