Skip to content

Instantly share code, notes, and snippets.

View riamf's full-sized avatar
🎯
Focusing

Pawel Kowalczuk riamf

🎯
Focusing
View GitHub Profile
struct MaxHeap<T: Comparable>: CustomStringConvertible {
var heap: [T] = []
var size: Int {
return heap.count
}
var description: String {
return "\(heap)"
}
@riamf
riamf / String+Utils.swift
Created July 15, 2018 09:27
Some String utils for accessing substrings
extension String {
subscript(idx: Int) -> Character {
let i = index(startIndex, offsetBy: idx)
return self[i]
}
subscript(range: CountableRange<Int>) -> String {
let s = index(startIndex, offsetBy: range.lowerBound)
let e = index(startIndex, offsetBy: range.upperBound)
return String(self[s..<e])
@riamf
riamf / diff.sh
Created October 8, 2017 17:41
Swift lint on all swift files from git diff
git diff origin/master --name-only | grep '\.swift' | xargs -I _path swiftlint --path "./_path"
@riamf
riamf / ch7_ruby_programming_language.md
Created February 22, 2017 18:03
Summary of chapter 7 Classes and Modules from Ruby Programming Language by David Flanagan; Yukihiro Matsumoto

#Ruby Programming Language

#Chapter 7 Classes and Modules

Defining a simple class

  • Keywords to define class: def, class
  • Class constructor can be defined with def initialize example of Point class:
@riamf
riamf / ch6_ruby_programming_language.md
Created February 15, 2017 19:29
Summary of chapter 6 Methods, Procs, Lambdas, and Closures from Ruby Programming Language by David Flanagan; Yukihiro Matsumoto

#Ruby Programming Language

#Chapter 6 Methods, Procs, Lambdas, and Closures

##Defining methods

  • to define method use def followed by method name
  • put method parameters in round brackets ()
  • Abnormal method termination is when method raises exception
  • If method terminates normally then last expression evaluated in method body will be method invocation value
@riamf
riamf / first.rb
Created February 1, 2017 18:42
Ruby script VERY SIMPLE counting functions in swift project file
#!/usr/bin/ruby
require 'find'
funcHash = Hash.new
functions = Array.new
files = Array.new
Dir.glob("**/*") { |path|
swift_file = path if path =~ /.*\.swift$/
@riamf
riamf / RandomColorExtension.swift
Created January 24, 2017 17:25
RandomColorExtension For Swift
extension UIColor {
class func random() -> UIColor {
let randomRed:CGFloat = CGFloat(drand48())
let randomGreen:CGFloat = CGFloat(drand48())
let randomBlue:CGFloat = CGFloat(drand48())
return UIColor(red: randomRed, green: randomGreen,
blue: randomBlue, alpha: 1.0)
@riamf
riamf / NSURLQueryParams.swift
Last active January 23, 2017 16:37
Cheeky way to get any parameter you want from NSURL GET query.
extension NSURL {
func query(parameter forKey:String, separator: String) -> String? {
return query?.components(separatedBy:
CharacterSet(charactersIn: separator)).first(where: {
$0.removingPercentEncoding?.hasPrefix(forKey) == true
})?.replacingOccurrences(of: forKey, with: "")
}
}
let url = NSURL(string: "https://www.google.pl/?gfe_rd=cr&ei=zjCGWJ33OsTi8Aef1qf4Cg")