Skip to content

Instantly share code, notes, and snippets.

View frozzare's full-sized avatar
😎
Focusing

Fredrik Forsmo frozzare

😎
Focusing
View GitHub Profile
root = true
[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
@frozzare
frozzare / request.swift
Created June 6, 2014 22:42
Example of a web request class in Swift
import Foundation
class Request : NSObject {
var url : NSURL? = nil
var request : NSMutableURLRequest? = nil
var response : NSHTTPURLResponse? = nil
var data: NSMutableData? = nil
var done: (NSError?, NSData, NSString?) -> () = { (_, _, _) -> () in }

Keybase proof

I hereby claim:

  • I am frozzare on github.
  • I am frozzare (https://keybase.io/frozzare) on keybase.
  • I have a public key ASAu0jk21efZkw07DoY2EDMh07y_9lAYvXG95G0z98CooAo

To claim this, I am signing this object:

@frozzare
frozzare / int.swift
Last active October 17, 2018 06:32
Example of how to create own extension on int type in Swift
extension Int {
func times (iterator: () -> Void) {
for _ in 0..self {
iterator()
}
}
func downto (to : Int, iterator: (Int) -> Void) {
var num : Int = self
@frozzare
frozzare / template.swift
Last active July 24, 2018 15:54
Example of string replacement in Swift with a dictionary
import Foundation
class Template {
class func render (var str: String, dict: Dictionary<String, String>) -> String {
for (key, value) in dict {
str = str.stringByReplacingOccurrencesOfString("{\(key)}", withString: value)
}
return str
}
package main
// reactWrapper fix issues with dynamic routes created
// in `react-router` so we don't get a 404 page.
//
// usage: http.Handle("/", reactWrapper(http.FileServer("path/to/public")))
func reactWrapper(fs http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
staticIndex := strings.Index(req.URL.Path, "/static/")
@frozzare
frozzare / array.swift
Created June 8, 2014 18:43
Example how to extend array type in Swift
import Foundation
extension Array {
/**
* Get first item in array.
*
* @return First item in array.
*/
@frozzare
frozzare / Capistrano-Deployment-Recipe.rb
Created January 25, 2012 11:40 — forked from mrrooijen/Capistrano-Deployment-Recipe.rb
a "base" Capistrano Rails Deployment Recipe. Use it to deploy your Rails application. It is also easily expandable. So feel free to grab this Recipe and add your own tasks/customization!
# Guide
# Configure the essential configurations below and do the following:
#
# Repository Creation:
# cap deploy:repository:create
# git add .
# git commit -am "initial commit"
# git push origin master
#
# Initial Deployment:
@frozzare
frozzare / file.swift
Created June 7, 2014 10:33
Example of how to create a file class with read, write and exists functions
import Foundation
class File {
class func exists (path: String) -> Bool {
return NSFileManager().fileExistsAtPath(path)
}
class func read (path: String, encoding: NSStringEncoding = NSUTF8StringEncoding) -> String? {
if File.exists(path) {
@frozzare
frozzare / regex+string.swift
Created June 11, 2014 11:01
Regex example
import Foundation
extension String {
func exec (str: String) -> Array<String> {
var err : NSError?
let regex = NSRegularExpression(pattern: self, options: NSRegularExpressionOptions(0), error: &err)
if err {
return Array<String>()
}
let nsstr = str as NSString