Skip to content

Instantly share code, notes, and snippets.

class Array
def random_element
self[Random.rand(length)]
end
end
namespace :events do
desc "Do stuff every hour"
task every_hour: :environment do
[self observe:UIDeviceOrientationDidChangeNotification on:@selector(orientationChanged:)];
- (NSPredicate *)predicateFromSearchOptions:(SearchOptions *)searchOptions {
NSMutableArray *formatParts = [NSMutableArray array];
NSMutableArray *args = [NSMutableArray array];
// viewport
[formatParts addObjectsFromArray:@[
@"latitude >= %@",
@"latitude <= %@",
@"longitude >= %@",
@"longitude <= %@"
@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}"
@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 / 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 / gist:1709c3b6623cc77a4d65
Created November 18, 2014 18:24
smen in python
def filterX(image, region):
return 1.0
def filterY(image, region):
return 2.0
_filters = {
"principalComponentX" : filterX,
"principalComponentY" : filterY
@andrei512
andrei512 / google_bot.rb
Created December 3, 2014 18:17
Google bot
require 'watir'
require 'watir-webdriver'
require 'nokogiri'
# require 'os'
require 'json'
query_string = ARGV[0]
# if OS.linux?
# # no more ui
@andrei512
andrei512 / hack.swift
Created January 11, 2015 20:04
factory hack
class A {
}
class B {
}
var factory: [String:()->(AnyObject)] = [
"A" : {
var n = 12
var bile = [3, 4, 6, 7, 8, 9, 2, 1, 10, 18, 22, 26]
var extrase = [2, 9, 3, 4, 22, 6]
extrase.sort(<)
bile.sort(<)
var minBall = extrase[0]