Skip to content

Instantly share code, notes, and snippets.

View jplazcano87's full-sized avatar
💭
Learning

Juan Pablo Lazcano jplazcano87

💭
Learning
  • Santiago, Chile
View GitHub Profile
@jplazcano87
jplazcano87 / validator.swift
Last active January 16, 2023 23:44
Rut validator chile
import Foundation
enum RutError: ErrorType{
case InvalidRut(message : String)
}
class FormValidator: NSObject {
static func validateRut(value : String) throws ->String {
//clean rut
@jplazcano87
jplazcano87 / AppHelper.java
Created September 5, 2016 14:29 — forked from anggadarkprince/AppHelper.java
Upload file with Multipart Request Volley Android
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import java.io.ByteArrayOutputStream;
/**
* Sketch Project Studio
* Created by Angga on 12/04/2016 14.27.
*/
public class AppHelper {
@jplazcano87
jplazcano87 / gist:db55f8bc41ee7f50d229663f4dc0b5a0
Created August 25, 2016 15:00 — forked from stuart11n/gist:9628955
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@jplazcano87
jplazcano87 / httpserver.py
Created August 24, 2016 18:06
SimpleHttpServer with ip and port
import sys
from SimpleHTTPServer import SimpleHTTPRequestHandler
import BaseHTTPServer
def test(HandlerClass=SimpleHTTPRequestHandler,
ServerClass=BaseHTTPServer.HTTPServer):
protocol = "HTTP/1.0"
host = ''
import UIKit
import XCPlayground
class ViewController: UIViewController {
func action() { print("Bing!") }
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .whiteColor()
@jplazcano87
jplazcano87 / SendMail.swift
Last active March 9, 2016 13:37
Send mail using swift
//
// SendMail.swift
// SendEmail with attachment
//
// Created by Spaceghost on 3/09/16.
// Copyright (c) 2016 Spaceghost. All rights reserved.
//
import UIKit
import MessageUI
@jplazcano87
jplazcano87 / test.playground
Created February 11, 2016 14:01
Ternanry operator in swift 2
var a:Int?
let b = 2
var output:Int?
//a is nil here
output = a ?? b
print("Value of Output is \(output!)")
//a is assigned value of b
@jplazcano87
jplazcano87 / cell.md
Created January 11, 2016 13:02
Cell with protocols and generics

iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

A common task when developing iOS apps is to register custom cell subclasses for both UITableView and UICollectionView. Well, that is if you don’t use Storyboards, of course.

Both UITableView and UICollectionView offer a similar API to register custom cell classes:

public func registerClass(cellClass: AnyClass?, forCellWithReuseIdentifier identifier: String)
public func registerNib(nib: UINib?, forCellWithReuseIdentifier identifier: String)
@jplazcano87
jplazcano87 / compres+uiimage.swift
Created December 29, 2015 19:22
Compress image data swift
extension UIImage {
var uncompressedPNGData: NSData { return UIImagePNGRepresentation(self)! }
var highestQualityJPEGNSData: NSData { return UIImageJPEGRepresentation(self, 1.0)! }
var highQualityJPEGNSData: NSData { return UIImageJPEGRepresentation(self, 0.75)! }
var mediumQualityJPEGNSData: NSData { return UIImageJPEGRepresentation(self, 0.5)! }
var lowQualityJPEGNSData: NSData { return UIImageJPEGRepresentation(self, 0.25)! }
var lowestQualityJPEGNSData:NSData { return UIImageJPEGRepresentation(self, 0.0)! }
}
//usage
@jplazcano87
jplazcano87 / createDoneButton.swift
Created December 28, 2015 15:13
Add Done Button to Numeric pad iOS (Swift)
@IBOutlet weak var txtNumber: UITextField!
override func viewDidLoad()
{
super.viewDidLoad()
//--- add UIToolBar on keyboard and Done button on UIToolBar ---//
self.addDoneButtonOnKeyboard()
}