Skip to content

Instantly share code, notes, and snippets.

@Galarius
Galarius / GMDEditor.py
Last active August 29, 2015 14:04
GMDEditor.py
# coding: utf-8
#-----------------------------
# Copyright (c) <Ilya Shoshin>
# <2014>
#-----------------------------
import ui
from markdown2 import markdown
#-----------------------------
# consts
@Galarius
Galarius / dispatch.m
Last active August 29, 2015 14:09
multithreading in iOS
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
// Delay execution of block for 1 second.
});
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Execution of block in the background thread.
});
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Execution of block in the background thread.
// wait until completion functions get called by method inside loop.
for(Object *o in objects)
{
__block BOOL block = YES;
[self applyMethod:o success:^(id result) {
//...
block = NO;
} failure:^(NSError *error) {
@Galarius
Galarius / django_test_api.py
Last active August 29, 2015 14:10
Test api with auth-key and user
# Every request to api requires an auth-key in header in this example.
# Example of how to perform api testing with such authentication.
# django 1.7
from django.apps import apps
from django.conf import settings
from django.test.client import RequestFactory
from api.user.views import UserKeyView
@Galarius
Galarius / regex_snippets.txt
Last active August 29, 2015 14:14
regex snippets
http://regexone.com/
------------------------------------
task:
match text 3.14529
match text -255.34
match text 128
match text 1.9e10
match text 123,340.00
skip text 720p
@Galarius
Galarius / custom_ios_app_version.sh
Last active August 29, 2015 14:19
Build app version using the latest hg commit hash and datetime.
# Custom iOS app version
# @usage
# 1. Select: your Target in Xcode
# 2. Select: Build Phases Tab
# 3. Select: Add Build Phase -> Add Run Script
# 4. Paste code below in to new "Run Script" section
# 5. Drag the "Run Script" below "Link Binaries With Libraries"
# 6. Insure that LastCommitHash and LastBuildDate are in your app plist file.
# 7. Somewhere in your obj-c code paste:
# + (NSString *)appVersionCommitHash {
@Galarius
Galarius / delegate_responds_cache.m
Last active August 29, 2015 14:21
caching whether a delegate responds to a selector
@protocol SomeDelegate <NSObject>
- (void)someMethod:(id)item;
@end
@interface SomeInterface : NSObject
@property (nonatomic, weak) id <SomeDelegate> delegate;
@end
@implementation SomeInterface {
struct {
@Galarius
Galarius / TheGashlyCodeTinies.txt
Created August 30, 2015 16:26
The GashlyCode Tinies
A is for Amy whose malloc was one byte short
B is for Basil who used a quadratic sort
C is for Chuck who checked floats for equality
D is for Desmond who double-freed memory
E is for Ed whose exceptions weren’t handled
F is for Franny whose stack pointers dangled
G is for Glenda whose reads and writes raced
@Galarius
Galarius / Setting _QT_in_Xcode.md
Created March 15, 2016 17:32
Setting QT in Xcode
path1 = 'text_ru.txt'
path2 = 'text_ru.uppercase.txt'
f = open(path1, 'r')
w = open(path2, 'w')
lines = f.readlines()
lines = [unicode(line.decode('utf-8')) for line in lines]
lines = [line.upper() for line in lines]
lines = [line.encode('utf-8') for line in lines]
w.writelines(lines)
w.close()