Skip to content

Instantly share code, notes, and snippets.

View arisris's full-sized avatar
👨‍🦱
Open to work

Aris Riswanto arisris

👨‍🦱
Open to work
View GitHub Profile
@arisris
arisris / Component.kt
Last active August 26, 2022 23:32
Datastore Preferences Composable
@Composable
fun TestPrefs() {
val (count, isLoading, setCount) = rememberIntPreferences("counter", 0)
Column {
Text("Current Count: ${if (isLoading) "loading" else count}")
Button(onClick = { setCount(count+1) }) {
Text("Increment by 1")
}
Button(onClick = { setCount(count-1) }) {
@arisris
arisris / post.md
Created March 10, 2022 04:37
ucfirst(); lcfirst(); ucwords(); in typescript
const ucFirst = (str: string) =>
  str
    .split("")
    .map((v, i) => (i === 0 ? v.toUpperCase() : v))
    .join("");
const lcFirst = (str: string) =>
  str
    .split("")
 .map((v, i) => (i === 0 ? v.toLowerCase() : v))
@arisris
arisris / post.md
Last active March 10, 2022 04:27
Experiment Using Deno deploy and Oak
import { Application, Router } from "https://deno.land/x/oak@v10.4.0/mod.ts";

const app = new Application();
const router = new Router();

// routes
router.get("/", ({ response }: { response: Response }) => {
    const data = `<h3>Hello Deno</h3>`;
 response.headers.set("content-type", "text/html");
@arisris
arisris / post.md
Last active March 10, 2022 04:29
Detect detect file type in codemirror mode
const loadMode = (editor, filename: string) => {
    if (!editor) return;
    const CodeMirror = window.CodeMirror;
    // @ts-ignore
    window.CodeMirror.modeURL = scriptCfg.baseUrl + "mode/%N/%N.min.js";
    var val = filename,
      m: any[],
      mode: string,
      spec: string | CodeMirror.ModeSpec<CodeMirror.ModeSpecOptions>;
@arisris
arisris / post.md
Last active March 10, 2022 04:30
Simple State Management Using React Hooks, Inpired By Hyperapp

useState.js

import { createContext, useContext, useState, useMemo } from 'react';

export const createStore = (state, actions) => {
  const set = (obj) =>
    obj && typeof obj === 'object'
      ? ((state = { ...state, ...obj }), state)
      : state;
  const newActions = Object.keys(actions)