Skip to content

Instantly share code, notes, and snippets.

View susilolab's full-sized avatar

Agus Susilo susilolab

View GitHub Profile
@susilolab
susilolab / rust_compile.ex
Created September 26, 2019 05:59
Script untuk mengkompil script rust dengan menyimpan file yg g bisa dikompil
defmodule RustCompile do
@rust_path "D:/var/Rust/hello"
@rust_target "D:/var/Rust/hello/bin"
def get_files(path_name) do
with {:ok, files} <- File.ls(path_name) do
files
else
{:error, reason} ->
reason
@susilolab
susilolab / rename_book.rs
Created September 26, 2019 06:01
Script untuk merename file ebook yang berektensi rar
use std::env;
use std::path::Path;
use std::fs;
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
println!("Invalid argumen!.\nCoba jalankan seperti ini: rename_book /tmp");
std::process::exit(1);
}
@susilolab
susilolab / loop_list.erl
Created September 26, 2019 17:41
Looping array/list di erlang
% hello world program
main(_Args) ->
L = [1,2,3,4,5],
% Function = fun(Elem) -> io:fwrite(Elem) end,
lists:foreach(fun(Elem) -> io:fwrite("~p~n", [Elem]) end, L).
@susilolab
susilolab / hello.erl
Last active September 27, 2019 02:29
Hello erlang
% hello world program
% jalankan dengan escript.exe di windows
% atau tambah #!/usr/bin/escript di linux
main(_Args) ->
hello(),
Listdir = ls(),
lists:foreach(fun(Elem) -> io:fwrite("~s~n", [Elem]) end, Listdir),
% Boolean
println(true and false),
% atom
@susilolab
susilolab / double.erl
Created September 27, 2019 02:30
Contoh modul erlang
%% modul double
%%
%% cara kompile
%% ```erlang
%% erlc double.erl
%% erl double.beam
%% 1> double:double(10).
%% ```
-module(double).
%% pub fn double
@susilolab
susilolab / watcher.ex
Created September 27, 2019 08:33
File monitoring sub genserver
defmodule Watcher do
use GenServer
def start_link(args) do
GenServer.start_link(__MODULE__, args)
end
def init(args) do
{:ok, watcher_pid} = FileSystem.start_link(args)
FileSystem.subscribe(watcher_pid)
@susilolab
susilolab / copy_lock_wp.ex
Created November 4, 2019 23:53
Menyalin wallpaper dari lock screen windows 10
defmodule CopyLockWp do
@path System.get_env("USERPROFILE") <> "\\AppData\\Local\\Packages\\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\\LocalState\\Assets"
@dst "D:\\var\\tmp"
def run() do
files = get_files(@path)
dst_dir = @dst <> "\\" <> rand_string()
if !File.exists?(dst_dir) do
File.mkdir_p!(dst_dir)
end
@susilolab
susilolab / gen_batch_cmd.ex
Created November 9, 2019 02:55
Generate windows cmd command from uutils.exe
defmodule GenBatchCmd do
@template ~s"""
@echo off
uutils.exe <%= cmd %> %*
"""
@dst "c:/Applications/bin"
def main() do
path = Path.expand(".") <> "/lscmd.txt"
cmd =
@susilolab
susilolab / sample.conf
Created November 25, 2019 07:13
contoh rewrite nginx
location /ecc4/ {
index index1.php;
if (!-e $request_filename) {
rewrite ^(/ecc4/.*)$ /ecc4/index1.php;
}
autoindex on;
client_max_body_size 10M;
}
@susilolab
susilolab / borrow-example.rs
Created January 21, 2020 07:10 — forked from Aatch/borrow-example.rs
An example and explanation of how to use lifetimes and borrowing to avoid copying, while maintaining safety.
extern mod extra;
use extra::json::*;
/*
* This function manages to do absolutely no copying, which is pretty cool.
*
* "What are all those `'r`s?" you ask. Well, they're liftime parameters. They
* indicate how long something lasts (before it's freed). They can't change how
* long something lives for, they only allow you to tell the compiler stuff it