Skip to content

Instantly share code, notes, and snippets.

View luish's full-sized avatar

Luis H. Sousa luish

View GitHub Profile
@luish
luish / build.gradle
Created February 4, 2020 12:54
Android: Avoid compressing TensorFlow models
android {
aaptOptions {
noCompress "tflite"
noCompress "lite"
}
}
@luish
luish / kotlin.md
Last active January 22, 2020 15:18

Kotlin

  1. Elvis operator
val data = response?.body
val title: String = data?.title ?: 'Page'
  1. Strings templates
@luish
luish / rust-vs-swift.md
Last active August 4, 2016 12:07
A few notes while learning a bit of Rust

So comparing Rust to Swift, we have:

Traits = protocols

struct Circle {
    x: f64,
    y: f64,
    radius: f64,
}
import Foundation
struct Linguistic {
typealias LinguisticTag = (token: String, tag: String)
static func tags(text: String, range: NSRange? = nil, language: String = "en") -> [LinguisticTag] {
let options: NSLinguisticTaggerOptions = [.OmitWhitespace, .OmitPunctuation, .JoinNames]
let schemes = NSLinguisticTagger.availableTagSchemesForLanguage(language)
import Foundation
struct Math {
static func standardDeviation(values: [Double]) -> Double {
let squaredAvgDiff = values.map { pow($0 - average(values), 2)}
let sum = squaredAvgDiff.reduce(0) {$0 + $1}
return sqrt(sum / Double(values.count))
}
protocol StringType {}
extension String: StringType {}
extension Optional where Wrapped: StringType {
var something: Int {
switch self {
case .None: return 10
case .Some(_): return 20
}
}

More lenient subscript methods over Collections

Introduction

This proposal seeks to provide more lenient subscript

@luish
luish / save_image_from_url.py
Last active December 20, 2015 11:59
Django: save an image from URL (works on Amazon S3)
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
import os
import uuid
import urllib
def save_image_from_url(url):