Skip to content

Instantly share code, notes, and snippets.

View CanTheAlmighty's full-sized avatar

Jose Canepa CanTheAlmighty

  • Turingo SpA
  • Chile
View GitHub Profile
@CanTheAlmighty
CanTheAlmighty / DataFormatter.swift
Last active August 28, 2015 19:30
Allows to turn NSData into String with the desired encoding, and also provides a convenient way to get an UnsafeBufferPointer from NSData
extension NSData
{
/// Creates a length-delimited, byte buffer
var buffer : UnsafeBufferPointer<UInt8> { get { return UnsafeBufferPointer(start: UnsafePointer<UInt8>(self.bytes), count: self.length) }}
}
extension String
{
/// Initializes a string from the given data
init?(data : NSData, encoding : NSStringEncoding)
@CanTheAlmighty
CanTheAlmighty / keybase.md
Created August 12, 2014 22:45
Keybase nonsense

Keybase proof

I hereby claim:

  • I am CanTheAlmighty on github.
  • I am can (https://keybase.io/can) on keybase.
  • I have a public key whose fingerprint is 2F82 5F81 6083 839E A2C3 577F 18F1 8091 E10F 6777

To claim this, I am signing this object:

@CanTheAlmighty
CanTheAlmighty / rubyism.swift
Last active August 29, 2015 14:16
Swift Rubyisms
extension Int
{
func times(f :(Int) -> ())
{
for i in 0..<self
{
f(i)
}
}
}

agnoster.zsh-theme

A ZSH theme optimized for people who use:

  • Solarized
  • Git
  • Unicode-compatible fonts and terminals (I use iTerm2 + Menlo)

For Mac users, I highly recommend iTerm 2 + Solarized Dark

@CanTheAlmighty
CanTheAlmighty / .gitconfig
Last active August 29, 2015 14:21
Pretty log format
[alias]
llg = log --pretty=format:'%Cgreen%h%Creset %ad (%an) %s' --graph --date=relative
@CanTheAlmighty
CanTheAlmighty / UIColor+Hex.swift
Created November 10, 2015 20:04
UIColor initializer from Hex number, in swift.
import UIKit
public extension UIColor
{
class func components(alphaHex hex : UInt32) -> (r:UInt8, g:UInt8, b:UInt8, a:UInt8)
{
let r = UInt8((hex & 0xFF000000) >> 24)
let g = UInt8((hex & 0x00FF0000) >> 16)
let b = UInt8((hex & 0x0000FF00) >> 8)
let a = UInt8((hex & 0x000000FF))
@CanTheAlmighty
CanTheAlmighty / xcode-snippet-viewinit.swift
Created September 7, 2016 14:33
Snippet for xcode, frequently used init with coder/frame combo, plus a prepareSubviews() method to do common initialization
required init?(coder decoder: NSCoder)
{
super.init(coder: decoder)
prepareSubviews()
}
override init(frame: CGRect)
{
super.init(frame: frame)
prepareSubviews()
@CanTheAlmighty
CanTheAlmighty / AnimatedLayout.swift
Last active September 14, 2016 15:42
Layout that applies a rotational transform on scrolling
override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes?
{
guard let collectionView = collectionView else { return nil }
let attributes = OnboardingTutorialAttributes(forCellWithIndexPath: indexPath)
// Bounds independant of scroll offset
let bounds = CGRect(origin: CGPoint.zero, size: collectionView.frame.size)
var frame : CGRect = CGRect.zero
@CanTheAlmighty
CanTheAlmighty / KeywordFormatterPlayground.swift
Created November 28, 2016 14:34
Provides Keyword-formatting to the String class
String(format: "The value of life is %(life)$d", ["life":42])
// "The value of life is 42"
String(format: "¿Dónde está %(firstname)$@ %(lastname)$@?", ["firstname":"Carmen", "lastname":"San Diego"])
// "¿Dónde está Carmen San Diego?"
String(format: "PI is %(pi)$.4f", ["pi":Double.pi])
// "PI is 3.1416"
String(format: "But PI can also be %(pi)$.f, or %(pi)$.5f, depending how you format it", ["pi":Double.pi])
@CanTheAlmighty
CanTheAlmighty / 0task.json
Created February 22, 2017 15:15
Tiny Little Task
{
"activity_tree":{
"uuid":"c5fe79ec-285f-4c72-a438-9b930e776105",
"name":"Tarea para probar executions",
"core_activity":false,
"instructions":"Verificar que haya registro de esta tarea en la tabla executions",
"company_uuid":"ab30c859-9d04-4993-b7f6-8b8c9f0b6561",
"creator_uuid":"1302e9d1-df3c-4e4b-891f-7670a1f1db18",
"reference_file":"development-neo-frogmi/company_ab30c859-9d04-4993-b7f6-8b8c9f0b6561/activity_c5fe79ec-285f-4c72-a438-9b930e776105/assets/14876918417d83730f_kat_von_d_5.jpg",
"respond_after_deadline":false,