Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View chakrit's full-sized avatar

Chakrit Wichian chakrit

View GitHub Profile
@chakrit
chakrit / reconstruct.cue
Created May 14, 2023 15:09
CUE script for breaking down a value, appending an item to the leaf element, and reconstructing back the original value.
input: {
outer: {
inner: [
{item: "one", values: [3, 2, 1]},
{item: "two", values: [1, 2, 3]},
{item: "three", values: [7, 8, 9]},
]
innernope: "innernope"
}
unrelated: "unrelated"
package main
import (
"bufio"
"fmt"
"log"
"os"
"strconv"
"unicode"
)
1
2
3 fizz
4
5 buzz
6 fizz
7
8
9 fizz
10 buzz
#!/bin/sh
apt-get remove -y docker docker-engine docker.io containerd runc
apt-get update
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
@chakrit
chakrit / api.go
Created May 4, 2021 13:17 — forked from narze/gov-project-generator.rb
gov-project-generator
package main
import (
"crypto/rand"
"encoding/binary"
"encoding/json"
"io/ioutil"
"log"
"net/http"
"strings"
@chakrit
chakrit / PageStreamer.java
Created February 23, 2021 08:57
Converting Spring Page<T> to Stream<T>
package com.github.chakrit;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import java.util.function.Function;
import java.util.stream.Stream;
/**
module Main exposing (..)
import Browser
import Html exposing (div, input, p, span, strong, text)
import Html.Attributes exposing (value)
import Html.Events exposing (onInput)
type alias Model =
String
@chakrit
chakrit / gendiff.go
Last active July 5, 2019 15:52
Generic Diff algorithm in Go.
package gendiff
type Op int
const (
noOp = Op(iota)
Match
Delete
Insert
)
@chakrit
chakrit / Base64.elm
Last active June 11, 2019 16:00
Base64 URL encoding
module Base64 exposing
( base64FromBytes
, base64ToBytes
, fromBase64String
, toBase64String
)
import Bitwise as Bits
import Bytes exposing (Bytes)
import Bytes.Decode as D
@chakrit
chakrit / elmgroupof.elm
Created June 11, 2019 15:28
Elm groupOf function
groupOf : Int -> List a -> List (List a)
groupOf count list =
let
len =
List.length list
in
if len >= count then
List.take count list :: (groupOf count <| List.drop count list)
else if len > 0 then