Skip to content

Instantly share code, notes, and snippets.

View Edudjr's full-sized avatar
🏠
Working from home

Eduardo Domene Junior Edudjr

🏠
Working from home
  • Mercado Livre
  • Sao Paulo
View GitHub Profile
@Edudjr
Edudjr / classMiniJSON.js
Last active April 4, 2016 23:36
MiniJSON example using Classes
#pragma strict
import MiniJSON;
import System.Collections.Generic;
class JsonData { // UnityScript only; impossible in JavaScript
var root : Dictionary.<String,System.Object>; //root of string: root = {"data":"data",...}
var array : List.<System.Object>;
var object : Obj; //another json string
var string : String;
@Edudjr
Edudjr / ImageUploader.swift
Last active April 13, 2016 21:38
This is an example of how to use Alamofire to upload an image to a server.
import Foundation
import Alamofire
import ModelRocket
class ImageUploader {
static func uploadImage(image : UIImage,
parameters: [String: String]? = nil,
completionSuccess: (result: JSON) -> Void,
completionError: (error: NSError) -> Void) {
@Edudjr
Edudjr / datasources.json
Last active September 5, 2022 02:02
A script for loopback that automatically creates the folders and models from a database in postgresql. It also exposes the models to the Explorer API.
{
"dbname": {
"host": "localhost",
"port": 5432,
"database": "mydatabase",
"password": "user123",
"name": "dbname",
"user": "user",
"connector": "postgresql"
}
@Edudjr
Edudjr / prettyPrint.swift
Created February 9, 2017 12:45
Swift 3 JSON pretty printing
//Function to pretty-print Json Object in Swift 3
func prettyPrint(with json: [String:Any]) -> String{
let data = try! JSONSerialization.data(withJSONObject: json, options: .prettyPrinted)
let string = NSString(data: data, encoding: String.Encoding.utf8.rawValue)
return string as! String
}
@Edudjr
Edudjr / Dictionary+Extension.swift
Last active April 7, 2022 17:14
A Swift 3 extension for pretty-printing JSON (in swift: [String: Any])
// Dictionary/JSON Extension
// Pretty Print Json Objects
//
// Created by Domene on 10/02/17.
//
import Foundation
extension Dictionary where Key == String, Value == AnyObject {
func prettyPrint() -> String{
@Edudjr
Edudjr / closure_example.js
Last active March 4, 2017 22:02
Examples of using 'this' context inside closures in Javascript
/*
* In this example we will examine three different ways
* of using 'this' context inside a closure in javascript
*
* Suppose we have a Player class in which we'll play the next
* song as soon as it receives an 'onended' event from the Audio object
*/
var Player = function(){
this.songList = ['path/to/audio1.mp3', 'path/to/audio2.mp3']
this.currentAudio = new Audio(this.songList[0])
@Edudjr
Edudjr / CustomMask.swift
Created March 17, 2017 13:56
A custom mask component for Swift 3.
//
// CustomMask.swift
//
// Created by Domene on 4/6/16.
//
import Foundation
/*
* CustomMask takes a string and returns it with the matching pattern
@Edudjr
Edudjr / SequenceCustomMaskTextfield.swift
Last active November 26, 2017 17:26
A component that takes multiple masks and automatically updates the textfield based on input's length
//
// SequenceCustomMaskTextField.swift
//
// Created by Domene on 02/02/17.
//
import Foundation
import UIKit
@objc protocol SequenceCustomMaskTextFieldDelegate : UITextFieldDelegate{
@Edudjr
Edudjr / ModalTransparentBackground.swift
Created April 23, 2018 18:23
Swift 4 Modal with transparent background
//
// Created by Eduardo Domene Junior on 19/04/2018.
// Make sure that your view controller in Attributes Inspector is marked as:
// * Presentation - Over the current context
// * Defines context
// * Provides context
import UIKit
class ModalTransparentBackground: UIViewController {
@Edudjr
Edudjr / Luhn.swift
Last active February 15, 2024 20:33 — forked from cwagdev/Luhn.swift
Luhn Algorithm in Swift 4.1
func luhnCheck(_ number: String) -> Bool {
var sum = 0
let digitStrings = number.reversed().map { String($0) }
for tuple in digitStrings.enumerated() {
if let digit = Int(tuple.element) {
let odd = tuple.offset % 2 == 1
switch (odd, digit) {
case (true, 9):