Skip to content

Instantly share code, notes, and snippets.

View mashingan's full-sized avatar

mashingan

View GitHub Profile
@mashingan
mashingan / AstarMain.java
Created June 27, 2023 21:58
A* search in Java and Ada
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
/*
Compile and run:
$ javac *.java
$ java AstarMain < input.txt
@mashingan
mashingan / declare.c
Last active November 13, 2022 21:46
Translate English declaration into C variable declaration
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "declare.h"
char* isFunc(char *s) {
char *ss = s;
removeWhiteSpaces(ss);
removeAorAn(ss);
@mashingan
mashingan / int-str-repr.c
Last active August 14, 2022 12:54
Contoh konversi integer menjadi string representasi
// need link with math lib hence link with -lm, e.g.:
// gcc int-str-repr.c -lm
// or simply using tcc like:
// tcc int-str-repr.c
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
package main
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"sync"
@mashingan
mashingan / murder-mystery.sql
Created June 11, 2020 06:55
A game SQL by setting with the story as detective to find out murder mystery using the information from SQL database; source: https://mystery.knightlab.com
/*
A crime has taken place and the detective needs your help. The detective gave you the crime scene report, but you somehow lost it. You vaguely remember that the crime was a ​murder​ that occurred sometime on ​Jan.15, 2018​ and that it took place in ​SQL City​. Start by retrieving the corresponding crime scene report from the police department’s database.
*/
-- check the available tables
SELECT name
FROM sqlite_master
where type = 'table';
-- crime_scene_report
@mashingan
mashingan / simplest_player.c
Created December 17, 2019 14:05
Simplest example of creating player using FFMpeg and SDL2. Currently with choppy audio playing.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include <windows.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
//#include <libavutil/frame.h>
#include <SDL2/SDL.h>
@mashingan
mashingan / poolconn.nim
Last active August 30, 2019 15:17
Pool connection test
import std/[deques, asyncdispatch, httpclient, tables, math, times]
type
Pool = ref object
conns: TableRef[int, AsyncHttpClient]
available: Deque[int]
method getConn(p: Pool): Future[(int, AsyncHttpClient)] {.base, async.} =
while true:
if p.available.len != 0:
package main
import (
"encoding/xml"
"flag"
"fmt"
"io"
"net/http"
"net/url"
"os"
package main
import (
"database/sql"
"fmt"
"log"
"math/rand"
"sync"
"sync/atomic"
"time"
@mashingan
mashingan / hsql_parser.hs
Last active December 9, 2018 13:44
(Broken) Exploration of `Text.ParserCombinators.ReadP` package used to parse SQL create table syntax.
module SqlParser where
import Text.ParserCombinators.ReadP
import Data.Char (isAlpha)
--import Data.String.Utils
import qualified Data.Text as T
import Data.List
import qualified Data.Set as Set
import qualified Data.Map as M
import Data.Maybe