Skip to content

Instantly share code, notes, and snippets.

View josete89's full-sized avatar

Jose Luis josete89

  • adidas-group
  • Zaragoza
View GitHub Profile
@josete89
josete89 / gist:952c89a5f7e1eff4734421a4f7d61a39
Last active August 29, 2017 07:22
Swift 4 Continuation Monad
// Playground - noun: a place where people can play
public func id<A>(x : A) -> A {
return x
}
public func error<A>(_ x : String) -> A {
assert(false, x)
}
/// The Continuation Monad
@josete89
josete89 / dataTransform.js
Created November 14, 2017 20:00
Data mapping with sanctuary
var data = {"id":1,"orderName":"Order from spain","teamName":"Portland penguins","orderType":"lock","discount":5,"contactName":"John doe","contactPhonePrefix":"+32","contactPhoneNumber":"3423232","contactEmail":"jhon.doe@mycompany.com","contactAddress":"830 Southwest","dealerId":"123","dealerNote":"Lorem ipsum","createdAt":"2017-11-13T16:40:12.000Z","updatedAt":"2017-11-13T16:40:12.000Z","products":[{"id":5,"externalId":"C77124","createdAt":"2017-11-13T16:40:12.000Z","updatedAt":"2017-11-13T16:40:12.000Z","OrderProduct":{"createdAt":"2017-11-13T16:40:12.000Z","updatedAt":"2017-11-13T16:40:12.000Z","orderId":1,"productId":5},"selectedSizes":[{"id":1,"technicalSize":520,"quantity":5,"createdAt":"2017-11-13T16:40:12.000Z","updatedAt":"2017-11-13T16:40:12.000Z","ProductSelectedSize":{"createdAt":"2017-11-13T16:40:12.000Z","updatedAt":"2017-11-13T16:40:12.000Z","productId":5,"selectedSizeId":1}}]}]}
var transformation = {"id":"id","order_name":"orderName","team_name":"teamName","order_type":"orderType","discount":
@josete89
josete89 / gist:fc6f648a8ea9e927d23cc1196a544ecc
Last active December 7, 2017 12:13
Crashing with MLMultiArray
 
func resize(to: CGFloat) -> UIImage {
let scale = to / self.size.width
let newHeight = self.size.height * scale
UIGraphicsBeginImageContext(CGSize(width: to, height: newHeight))
self.draw(in: CGRect(x: 0, y: 0, width: to, height: newHeight))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
@josete89
josete89 / transfer_learning.py
Last active December 7, 2017 21:04
coremltools error
from keras.engine import Model
from keras.layers import GlobalAveragePooling2D, Dense
from keras.optimizers import SGD
from keras.preprocessing.image import ImageDataGenerator
from keras.applications import InceptionV3
from keras.applications.inception_v3 import preprocess_input
from coremltools.converters.keras import convert
from keras.models import load_model
train_data_dir = "./../data/train"
import * as tf from '@tensorflow/tfjs'
const app = requiere('express')()
import '@tensorflow/tfjs-node'
tf.setBackend('tensorflow')
app.get('/model',(req,res) => {
const prediction = await model.predict(req['x']).data()
res.send(prediction)
})
from keras import regularizers
model = models.Sequential()
model.add(layers.Dense(16, kernel_regularizer=regularizers.l2(0.001),
activation='relu', input_shape=(10000,)))
model.add(layers.Dense(16, kernel_regularizer=regularizers.l2(0.001),
activation='relu'))
model.add(layers.Dense(1, activation='sigmoid'))
model = models.Sequential()
model.add(layers.Dense(16, activation='relu', input_shape=(10000,)))
model.add(layers.Dropout(0.5))
model.add(layers.Dense(16, activation='relu'))
model.add(layers.Dropout(0.5))
model.add(layers.Dense(1, activation='sigmoid'))
from keras.models import Sequential
from keras import models
model = Sequential()
...
# serialize model
model.save('my_model.hd5')
# later...
from coremltools.converters.keras import convert
from keras.models import Sequential
model = Sequential()
...
# In case the model accept a image as input will be more
# easier for iOS code declare in that way.
coreml_model = convert(model, image_input_names="input1")
coreml_model.save('my_model.mlmodel')
@josete89
josete89 / gist:57a7ef94f11b270c551944328a3694a5
Created September 4, 2018 14:27
Free monad for http request
class GetParam<A>{
readonly _tag: 'GetParam' = 'GetParam';
readonly _A!: A;
readonly _URI!: RequestLifeCycleFURI;
constructor(readonly url: string,readonly more: (param:either.Either<Error,string>)=> A){ }
}
class Validate<A> {
readonly _tag: 'Validate' = 'Validate';