Skip to content

Instantly share code, notes, and snippets.

View radi-cho's full-sized avatar

Radi Cho radi-cho

View GitHub Profile
@radi-cho
radi-cho / proguard-user.txt
Created February 5, 2019 09:30
Proguard config for solving the common Admob Unity error ClassNotFoundException ads.UnityAdListener
-keep class com.google.unity.** {
*;
}
-keep public class com.google.android.gms.ads.**{
public *;
}
-keep public class com.google.ads.**{
public *;
}
-keepattributes *Annotation*
@radi-cho
radi-cho / train-function.js
Created September 23, 2018 19:07
Check if training from scratch or retraining an existing model is needed.
// TFjs and gcs are using a lot of memory, so increasing it will speed up the functions
exports.train = functions
.runWith({ memory: "2GB" })
.https.onRequest(async (request, response) => {
const existJSON = await bucket.file("model.json").exists().then(ex => ex[0]);
const existBIN = await bucket.file("weights.bin").exists().then(ex => ex[0]);
if (!existJSON || !existBIN) {
const model = tf.sequential();
model.add(tf.layers.dense({ units: 2, inputShape: [vocabulary.length] }));
@radi-cho
radi-cho / trainAndSave.js
Created September 23, 2018 19:03
Method which is used to train and save the BoW model.
const trainSave = async (model, querySnapshot) => {
if (!querySnapshot.docs.length) return false;
const xs_data = querySnapshot.docs.map(doc => fitData(doc.data().text));
const ys_data = querySnapshot.docs.map(
doc => (doc.data().y === "positive" ? [1] : [0])
);
const xs = tf.tensor2d(xs_data);
const ys = tf.tensor2d(ys_data);
@radi-cho
radi-cho / linear-model-function.js
Created September 23, 2018 18:57
TF.js linear model inside Firebase Functions
exports.runLinearModel = functions.https.onRequest((request, response) => {
// Get x_test value from the request body
const x_test = Number(request.body.x);
// Check if the x value is number. Otherwise request a valid one and terminate the function.
if (typeof x_test !== "number" || isNaN(x_test))
response.send("Error! Please format your request body.");
// Define a model for linear regression.
const linearModel = tf.sequential();
@radi-cho
radi-cho / fitData.js
Created September 23, 2018 18:54
Bag of Words model built with tfjs. How it works, how to train it and use for predictions.
// simple vocabulary with positive and negative terms
const vocabulary = ["bad", "slow", "ugly", "overrated", "expensive", "wrong", "good", "amazing", "fast", "kind", "cheap"];
const fitData = string => {
const stringSplit = string.replace(/[^a-zA-Z ]+/g, "").split(" ");
const words = {};
stringSplit.forEach(ev => {
words[ev] =
typeof words[ev] === "number" ? (words[ev] += 1) : (words[ev] = 1);
@radi-cho
radi-cho / keyboard-button-positions.css
Created July 16, 2018 10:34
CSS Snipped for blogpost by Radi Cho - shadow positions
box-shadow: 45px 40px currentColor, 90px 40px currentColor,
135px 40px currentColor, 180px 40px currentColor, 225px 40px currentColor,
270px 40px currentColor, 315px 40px currentColor, 360px 40px currentColor,
405px 40px currentColor, 450px 40px currentColor, 495px 40px currentColor,
553px 40px currentColor, 573px 40px currentColor, 45px 80px currentColor,
90px 80px currentColor, 135px 80px currentColor, 180px 80px currentColor,
225px 80px currentColor, 270px 80px currentColor, 315px 80px currentColor,
360px 80px currentColor, 405px 80px currentColor, 450px 80px currentColor,
495px 80px currentColor, 540px 80px currentColor, 573px 80px currentColor,
45px 120px currentColor, 78px 120px currentColor, 123px 120px currentColor,
@radi-cho
radi-cho / keyboard-button-container-position.css
Created July 16, 2018 10:27
CSS Snipped for blogpost by Radi Cho - keyboard buttons and the disappearing shadows
/*
If we make it `display: none`, the shadows will disappear as well,
and the easiest solution will be something like this:
*/
left: -30px;
top: -30px;
@radi-cho
radi-cho / keyboard-button-container.css
Created July 16, 2018 10:20
CSS Snipped for blogpost by Radi Cho - keyboard buttons
.keyboard:before {
/* Don't forget the content */
content: "";
position: absolute;
width: 35px;
height: 30px;
border-radius: 3px;
border: 1px solid transparent;
color: lightgrey;
}
@radi-cho
radi-cho / keyboard-container.css
Created July 16, 2018 10:12
CSS Snipped for blogpost by Radi Cho - keyboard corpus
.keyboard {
position: absolute;
width: 600px;
height: 300px;
color: darkslategray;
border: 2px solid currentColor;
border-radius: 12px;
margin: 300px 10px 10px 65px;
transform: rotateX(30deg) rotateZ(0deg);
box-shadow: 2px 5px 12px currentColor;
// Before
import { RSGButton } from 'rsg-components'
import { RSGBox } from 'rsg-components';
import { RSGCheckbox, RSGLabel } from 'rsg-components'
import { RSGProgressBar as PB } from 'rsg-components'
// After 3.0.0-beta.1
import { Button } from 'rsg-components'
import { Box } from 'rsg-components';
import { Checkbox, Label } from 'rsg-components'