Skip to content

Instantly share code, notes, and snippets.

import Foundation
protocol Alphabet {
associatedtype AlphabetCharacter: Comparable, Hashable
func allCharacters() -> [AlphabetCharacter]
init()
@andrei512
andrei512 / GIFLoader.h
Created October 15, 2012 19:53
GIFLoader - simple GIF support for iOS
//
// GIFLoader.h
// AnimatedGifExample
//
// Created by Andrei on 10/15/12.
// Copyright (c) 2012 Whatevra. All rights reserved.
//
#import <Foundation/Foundation.h>
#include <stdio.h>
#define NNodes 22
int Sum, Min, x, y, n, m, c, f[NNodes], st[NNodes], a[NNodes][NNodes];
void back(int k) {
if(k == n + 1) {
if(a[st[n]][st[1]] > 0) {
Sum += a[st[n]][st[1]];
let a = "2"
prop_regex = /@property\s*\([^\)]+\)\s+(?<type>\w+(\s*\*)?)\s*(?<name>\w+)/
code = `pbpaste`
property_list = []
code.scan(prop_regex) do |match|
type, name = match
[self observe:UIDeviceOrientationDidChangeNotification on:@selector(orientationChanged:)];
class Array
def random_element
self[Random.rand(length)]
end
end
namespace :events do
desc "Do stuff every hour"
task every_hour: :environment do
@andrei512
andrei512 / ubiquitous.rb
Created January 16, 2014 15:48
ubiquitous ruby clipboard processing script
#!/usr/bin/env ruby
clipboard = `pbpaste`
if clipboard.match /https?:\/\/w?w?w?\.((youtube)|(listenonrepeat))\.com\/.*/
# Youtube / Listen on repeat
if clipboard["youtube"] != nil
clipboard["youtube"] = "listenonrepeat"
elsif clipboard["listenonrepeat"] != nil
clipboard["listenonrepeat"] = "youtube"
end
@andrei512
andrei512 / hack.m
Created January 10, 2014 11:47
hack for preventing multiple method calls in the same time. For example if you have a bug in your code that calls viewWillAppear: two times every time you can just copy/paste this code
// Invalidate a call if it's been less that 1 second since the last one
//=====================================================================
static NSDate *lastDate = nil;
NSDate *currentDate = [NSDate date];
if (lastDate != nil &&
[currentDate timeIntervalSinceDate:lastDate] < 1) {
return ;
}
lastDate = currentDate;
//=====================================================================
DERIVED_DATA_PATH = "~/Library/Developer/Xcode/DerivedData/"
def projects
`ls -al #{DERIVED_DATA_PATH}`.split("\n")[3..-1].map { |p|
ls_components = p.split(" ")
project_name = ls_components.last
if project_name != "ModuleCache"
project_name = project_name.split("-")[0..-2].join("-")
else