Skip to content

Instantly share code, notes, and snippets.

View aaripurna's full-sized avatar
💣
(_T_)

nawa aripurna aaripurna

💣
(_T_)
View GitHub Profile
@aaripurna
aaripurna / setup
Last active June 2, 2019 07:33
quick setup development setup for ubuntu derivatives distros
#!/bin/bash
set -e
update() {
sudo apt update #&& sudo apt upgrade -y
}
credential() {
sudo apt install make g++ git curl redis-server libgmp3-dev zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev postgresql postgresql-contrib libpq-dev -y
@aaripurna
aaripurna / sublime-config
Last active June 2, 2019 04:50
basic sublime text 3 config
#!/bin/bash
set -e
# clone sublime config from github
clone() {
git clone https://github.com/aaripurna/sublime-config.git ~/sublime-config
rm -rf sublime-config/.git
cd ~/.config/sublime-text-3/Installed\ Packages/
mv ~/sublime-config/* ./
@aaripurna
aaripurna / rails-editorconfig
Last active June 2, 2019 01:47
this is editor config for rails project
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
@aaripurna
aaripurna / editor-config-generator
Last active June 9, 2019 10:17
generate editor config for certain project
#!/bin/bash
set -e
export ror='https://gist.githubusercontent.com/aaripurna/56ff2ab5f6320984c105f337d500cd3f/raw'
get-config() {
link=${!1}
if [[ ! -z $link ]]; then
curl -L $link | tee $HOME/.editorconfig/$1
else
I am assuming that the modles will look like this
class Customer < ApplicationRecord
has_many :purcases
# Rest of the code
end
class Purcase < ApplicationRecord
has_one :discount_coupon_usage
# Rest of the code
{
"data": [
{
"code": "pos",
"name": "POS Indonesia (POS)"
},
{
"code": "jne",
"name": "Jalur Nugraha Ekakurir (JNE)"
},
@aaripurna
aaripurna / nullable.rs
Created July 23, 2021 15:38
Null handling in rust
// Sometimes will retun None
fn some_operation() -> Option<String> {
// Some operation that may return None
}
fn write_text() {
match some_iperation() {
Some(text) => println!("{}", text),
None => println!("There is nothing")
}
@aaripurna
aaripurna / pattern_matching.rs
Created July 23, 2021 16:08
Struct pattern patching
// Destructuring a struct
Person {
name: person_name,
age: person_age,
...
} = person;
println!("{}", person_name);
@aaripurna
aaripurna / error.rs
Created July 23, 2021 16:27
error handling rust
fn some_operation() -> Result<str, Error> {
if succeded() {
Ok("We did it")
} else {
Err(Error::from("this not working"))
}
}
fn main() {
match some_operation() {
@aaripurna
aaripurna / deep-match.rs
Created July 23, 2021 16:53
depp nessted match mattern
match connect_database() {
Ok(mut conn) => match conn.fetch_user() {
Ok(user) => conn.get_post(user.id) {
Ok(post) => conn.get_comments(post.id) {
Ok(_comments) => println!("We got the coments"),
Err(_) => println!("its error, no comment")
}
Err(_) => println!("Can't find post")
}
Err(_) => println!("Can't find user")