Skip to content

Instantly share code, notes, and snippets.

View jaumevn's full-sized avatar

Jaume Viñas Navas jaumevn

View GitHub Profile
@jaumevn
jaumevn / compression.swift
Last active May 17, 2021 16:57
Video Compression in Swift
func compress(videoPath : String, exportVideoPath : String, renderSize : CGSize, completion : (Bool) -> ()) {
let videoUrl = NSURL(fileURLWithPath: videoPath)
if (!existsFileAtUrl(videoUrl)) {
completion(false)
return
}
let videoAssetUrl = AVURLAsset(URL: videoUrl, options: nil)
@jaumevn
jaumevn / parsing-json.swift
Last active October 3, 2019 10:51
Parsing JSON - Encode
struct User {
var name: String
var username: String
var phoneNumber: String
}
struct User: Codable {
var name: String
var username: String
var phoneNumber: String
}
struct Device: Codable {
var name: String
var manufacturer: String
}
struct User: Codable {
var name: String
var username: String
var phoneNumber: String
var devices: [Device]
func decode(data: Data) throws -> User? {
do {
let decoder = JSONDecoder()
let user = try decoder.decode(User.self, from: data)
return user
} catch let error {
print(error)
return nil
}
}
struct Device: Codable {
var name: String
var manufacturer: String
}
struct User: Encodable {
var name: String
var username: String
var phoneNumber: String
var devices: [Device]
struct Device: Codable {
var name: String
var manufacturer: String
}
struct User: Encodable {
var name: String
var username: String
var phoneNumber: String
var devices: [Device]
@jaumevn
jaumevn / J8TToken.sol
Last active January 23, 2018 12:23
J8TToken.sol
pragma solidity ^0.4.17;
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
function mul(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
@jaumevn
jaumevn / custodian.sol
Created February 1, 2018 17:28
Hodlers Dapp
pragma solidity ^0.4.18;
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
pragma solidity ^0.4.17;
contract J8TTokenConfig {
// The J8T decimals
uint8 public constant TOKEN_DECIMALS = 8;
// The J8T decimal factor to obtain luckys
uint256 public constant J8T_DECIMALS_FACTOR = 10**uint256(TOKEN_DECIMALS);
}