Skip to content

Instantly share code, notes, and snippets.

View JoonHoSon's full-sized avatar

JoonHo Son JoonHoSon

  • Incheon, Republic of Korea
View GitHub Profile

Rust Error Handling Cheatsheet - Result handling functions

Introduction to Rust error handling

Rust error handling is nice but obligatory. Which makes it sometimes plenty of code.

Functions return values of type Result that is "enumeration". In Rust enumeration means complex value that has alternatives and that alternative is shown with a tag.

Result is defined as Ok or Err. The definition is generic, and both alternatives have

@JoonHoSon
JoonHoSon / iframe.js
Created October 29, 2024 06:55 — forked from PechenkiUA/iframe.js
Youtube iframe contentWindow.postMessage command
document.querySelector('iframe').contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
@JoonHoSon
JoonHoSon / pre-push
Created September 6, 2023 12:54
pre-push-cargo-test
#!/bin/sh
export CARGO_HOME=$HOME/.cargo
echo "-------------------------------"
echo "Cargo test..."
echo "CARGO_HOEM : $CARGO_HOME"
echo "-------------------------------"
execute=$($CARGO_HOME/bin/cargo test --features local)
@JoonHoSon
JoonHoSon / pre-commit-cargo-fmt
Last active September 6, 2023 12:52 — forked from hryniuk/pre-commit-cargo-fmt
Git `pre-commit` hook that checks Rust code style with `cargo fmt`
#!/bin/bash
CARGO_HOME=/Users/joonho/.cargo
diff=$($CARGO_HOME/bin/cargo fmt -- --check)
result=$?
if [[ ${result} -ne 0 ]] ; then
cat <<\EOF
There are some code style issues, run `cargo fmt` first.
@JoonHoSon
JoonHoSon / jdtls.py
Created January 13, 2023 09:55
jdtls.py에서 lombok 활성화
###############################################################################
# Copyright (c) 2022 Marc Schreiber and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0.
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
@JoonHoSon
JoonHoSon / init.lua
Last active April 24, 2023 05:29
neovim init.lua
-- Install packer
local install_path = vim.fn.stdpath 'data' .. '/site/pack/packer/start/packer.nvim'
local is_bootstrap = false
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
is_bootstrap = true
vim.fn.system { 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path }
vim.cmd [[packadd packer.nvim]]
end
require('packer').startup(function(use)
@JoonHoSon
JoonHoSon / gist:58dda35455bf0ca56a8a1a5b7e32a4ec
Created October 20, 2021 09:47
Wildfly PostgreSQL JNDI 설정(CLI 이용)
$./jboss-cli.sh
connect
module-add --name=org.postgres --resources=/<path>/<to>/postgresql-x-x.jar --dependencies=javax.api,javax.transaction.api
/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgres",driver-class-name=org.postgresql.Driver)
data-source add --jndi-name=java:/<JNDI>/<NAME> --name=<NAME> --connection-url=jdbc:postgresql://<IP>:<PORT>/<DBNAME> --driver-name=postgres --user-name=<ID> --password=<PASSWORD>
@JoonHoSon
JoonHoSon / currency.js
Created September 24, 2021 05:42
Javascript currency format
target.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
@JoonHoSon
JoonHoSon / README.md
Created October 13, 2020 01:36 — forked from joyrexus/README.md
Vanilla JS equivalents of jQuery methods

Sans jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
@JoonHoSon
JoonHoSon / UIDeviceHardware.h
Created February 18, 2019 05:39 — forked from Jaybles/UIDeviceHardware.h
UIDeviceHardware - Determine iOS device being used
//
// UIDeviceHardware.h
//
// Used to determine EXACT version of device software is running on.
#import <Foundation/Foundation.h>
@interface UIDeviceHardware : NSObject
- (NSString *) platform;