Skip to content

Instantly share code, notes, and snippets.

@andrei512
andrei512 / gist:0800340f0508a8db77dd
Created October 12, 2014 22:50
class properties
class Tank {
class var bonusDamage: Double {
return Double(Upgrade.level) * 2.5
}
let baseDamage = 10.0
var damage: Double {
return self.baseDamage + Tank.bonusDamage
}
@andrei512
andrei512 / regexp.rb
Created May 28, 2014 14:03
get some phone mumbers :)
content = "Titlu stiintific: , Forma de exercitare a profesiei: CI, Modalitatea de exercitare a profesiei: T
Sediul profesional secundar: , Birou de lucru:
Telefon fix: , Telefon mobil: 0723384846, Fax: , E-mail:
Sediul profesional secundar: , Birou de lucru:
Telefon fix: 0263684846, Telefon mobil: 0723384846, Fax: , E-mail:
0723384
0723384846
072338484
@andrei512
andrei512 / boom.rb
Created February 7, 2014 16:59
send 1k requests to a site
require 'open-uri'
require 'net/http'
threads = []
target = "http://www.mindcoding.ro/"
boom_time = Time.new + 5
puts "boom time = #{boom_time}"
- (NSPredicate *)predicateFromSearchOptions:(SearchOptions *)searchOptions {
NSMutableArray *formatParts = [NSMutableArray array];
NSMutableArray *args = [NSMutableArray array];
// viewport
[formatParts addObjectsFromArray:@[
@"latitude >= %@",
@"latitude <= %@",
@"longitude >= %@",
@"longitude <= %@"
[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
@andrei512
andrei512 / NSURLRequest+cURL.h
Created January 6, 2014 13:20
NSURLRequest+cURL
#import <Foundation/Foundation.h>
@interface NSURLRequest (cURL)
- (NSString *)cURLCommand;
@end