Skip to content

Instantly share code, notes, and snippets.

View javipacheco's full-sized avatar

Javier Pérez Pacheco javipacheco

View GitHub Profile
@javipacheco
javipacheco / pixel_art.scad
Last active June 12, 2020 10:46
Script OpenScad para crear objetos 3D desde un array de pixeles
// mono
// data = [[-1, -1, -1, -1, -1, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1], [-1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1], [-1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1], [-1, -1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, -1, -1, -1], [1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, -1], [1, 1, 0, 1, 3, 2, 1, 1, 1, 3, 2, 1, 0, 1, 1, -1], [-1, 1, 0, 1, 2, 2, 1, 1, 1, 2, 2, 1, 0, 1, -1, -1], [-1, -1, 0, 1, 4, 4, 1, 1, 1, 4, 4, 1, 0, -1, -1, -1], [-1, -1, -1, 0, 1, 1, 1, 2, 1, 1, 1, 0, -1, -1, -1, -1], [-1, -1, -1, -1, 0, 0, 1, 1, 1, 0, 0, -1, -1, -1, -1, -1], [-1, 1, -1, -1, -1, -1, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1], [-1, 0, -1, -1, -1, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1], [-1, 0, 0, -1, -1, 0, 0, 1, 0, 0, -1, -1, -1, -1, -1, -1], [-1, -1, 0, 0, 0, 0, 1, 1, 1, 0, -1, -1, -1, -1, -1, -1], [-1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1], [-1, -1, -1, 0, 0, 1, 1, 0, 1, 1, 0, 0, -1, -1, -1, -1]];
// height = [3, 1, 2, 1, 1];
// mario flower power
// data = [[-1, -1, -1, -1, 0, 0, 0, 0,
@javipacheco
javipacheco / dice.scad
Last active October 27, 2019 20:41 — forked from a4099181/dice.scad
OpenSCAD: dice.
/*
* 6-sided play cube
*/
DRAW_DOTS = 0;
DRAW_CHATS = 1;
// font face
font_face="Arial";
// font style
@javipacheco
javipacheco / create_translate.py
Created June 14, 2019 11:19
Generating translating files
import json
import codecs
locales = ["es", "en", "pt", "de", "it", "hi"]
input_file = file("translations.json", "r")
data = json.loads(input_file.read().decode("utf-8-sig"))
for locale in locales:
loc = data['translations'][locale]
@javipacheco
javipacheco / translations.json
Created June 14, 2019 11:16
translations.json
{
"translations": {
"en": {
"hello": "Hello",
"world": "World"
},
"es": {
"hello": "Hola",
"world": "Mundo"
},
sealed class Notifications() {
// Main
data class NewsGetItemsNotification(val ex: Throwable) : Notifications()
// Navigation
data class NavigationNotification(val ex: Throwable) : Notifications()
}
sealed class Commands {
// Main
data class MainNavigationCommand(val item: MainNavigationState) : Commands()
// News
data class NewsGetItemsCommand(val limit: Int = 10) : Commands()
data class ReloadNewsCommand(val limit: Int = 10) : Commands()
@javipacheco
javipacheco / ViewModel_Notification.kt
Created May 23, 2018 20:55
Handling notifications on ViewModel
fun notification(notification: Notifications): DeferredK<Unit> = when (notification) {
is Notifications.NewsGetItemsNotification -> DeferredK {
viewState.postValue(ViewState.FailedViewState(notification.ex))
}
else -> notification.toDeferred()
}
@javipacheco
javipacheco / Activity.kt
Created May 23, 2018 20:54
Calling to ViewModel from Activity
newsModel.dispatch(NewsGetItemsCommand()).unsafeRunAsyncWithException {
newsModel.notification(Notifications.NewsGetItemsNotification(it))
}
sealed class ViewState {
object IdleViewState : ViewState()
object WaitingViewState : ViewState()
object SuccessViewState : ViewState()
data class FailedViewState(val throwable: Throwable) : ViewState()
@javipacheco
javipacheco / NewsModel.kt
Last active May 24, 2018 07:27
Getting news for ApiService on NewsModel
val newsState = State<States.NewsState>()
val viewState = State<ViewState>(ViewState.IdleViewState)
fun dispatch(command: Commands): DeferredK<Unit> = when (command) {
is Commands.NewsGetItemsCommand -> {
DeferredK.monad().binding {
val newsList = newsState.getValue()
if (newsList?.items?.isEmpty() == false) {
"Loading data from state".logD()
viewState.postValue(ViewState.SuccessViewState)