Skip to content

Instantly share code, notes, and snippets.

@exavolt
exavolt / modularizing-your-apps.md
Last active December 18, 2023 04:32
Modularizing your apps

Modularizing your apps

Why do we want modularize our apps? Jump to the last section of this article for the rationale.

Imagine we have a two app projects. One of them is a task management app (tasker) while the other is a chat app (messenger).

We have this for the tasker app:

.
├── models
@exavolt
exavolt / Dockerfile
Last active April 4, 2024 21:09
Containerized Hugo (extended) with VSCode devcontainer
FROM golang:1.13-alpine
# VARIANT can be either 'hugo' for the standard version or 'hugo_extended' for the extended version.
ARG VARIANT=hugo_extended
# VERSION can be either 'latest' or a specific version number
ARG VERSION=latest
RUN apk add --update --no-cache ca-certificates openssl git curl && \
case ${VERSION} in \
latest) \
@exavolt
exavolt / README.md
Last active September 16, 2021 07:34
ChoiceChipBar

Choice Chip Bar for Flutter

While Flutter already provides ChoiceChip, it's a bare-bone component. We would need to wire them ourselves to create a group of choices. This widget, ChoiceChipBar, means to provide a self-contained widget for a group of choice chips, so the ancestor widget won't need to manage the state; just provide the choices and a callback to onChanged.

Screenshot_1594966144 copy

@exavolt
exavolt / material_palette_generator.dart
Last active July 13, 2020 07:16
Generate a palette from an input color similar to the official tool found at https://material.io/inline-tools/color/
// source
// https://github.com/filipeglfw/material-palette-generator/blob/master/src/index.js
import 'dart:math' as math;
// Main API.
//
// generateMaterialPalette(RGBColor.fromInt(0xffe91e63)).map<Color>((c) => Color(c.toInt()));
//
List<RGBColor> generateMaterialPalette(RGBColor rgbColor) {
@exavolt
exavolt / theme_mode_app.dart
Last active September 29, 2020 18:36
Switch theme mode (system, light, dark) dynamically
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
// Wrap your application instance with this class.
//
// class MyApp extends StatelessWidget {
// // This widget is the root of your application.
// @override
// Widget build(BuildContext context) {
// return ThemeModeApp((BuildContext context, ThemeMode themeMode) {
@exavolt
exavolt / color_choice_bar.dart
Last active July 13, 2020 05:07
A color choice bar similar to Keep's and Instagram's
//
import 'package:flutter/material.dart';
class ColorChoiceController extends ValueNotifier<ColorChoiceValue> {
ColorChoiceController([int index])
: super(index != null ? ColorChoiceValue(index) : null);
Color get color => this.value?.color;
@exavolt
exavolt / go-git-log.go
Last active August 21, 2019 04:26
Nothing
package main
import (
"fmt"
"path/filepath"
"strings"
"gopkg.in/src-d/go-billy.v4/osfs"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing/cache"
@exavolt
exavolt / sdl2_opengl.c
Created April 11, 2012 16:36
Very basic SDL2 OpenGL application
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
@exavolt
exavolt / lineintersection.as
Created February 24, 2012 08:45 — forked from painquin/lineintersection.as
Line segment intersection in AS3
// ported from http://alienryderflex.com/intersect/
public static function LineIntersection(a:Point, b:Point, c:Point, d:Point):Point
{
var distAB:Number, cos:Number, sin:Number, newX:Number, ABpos:Number;
if ((a.x == b.x && a.y == b.y) || (c.x == d.x && c.y == d.y)) return null;
if ( a == c || a == d || b == c || b == d ) return null;
b = b.clone();

Di sini kita akan membahas seputar pergerakan object di dalam game yang digerakkan dengan cara mengklik titik tujuan kemana object harus bergerak. Cara input seperti ini banyak digunakan untuk game-game RTS dan RPG.

Secara garis besar bisa kita jelaskan sebagai: menggerakkan object ke arah yang dituju. Cukup simpel. Tapi kalo menggampangkan, hasilnya tidak seperti yang kita harapkan; misal, ketika sampai di tujuan, object-nya bergerak bolak-balik.

Semisal object yang akan kita gerakkan berada di posisi A. Kita ingin menggerakkan object ini ke titik B.

Pertama kali, simpan titik tujuan ini, koordinat titik B, sebagai atribute dari sang object.

Langkah selanjutnya kita lakukan adalah mengurangkan koordinat titik tujuan dengan koordinat titik awal. Di sini kita akan mendapatkan (non-normalized) vector dari titik awal ke titik tujuan.