Skip to content

Instantly share code, notes, and snippets.

View philipjkim's full-sized avatar

Soo Philip Jason Kim philipjkim

View GitHub Profile
@philipjkim
philipjkim / iter_test.rs
Last active March 15, 2024 00:15
Rust: Difference between iter(), into_iter(), and iter_mut()
#[test]
fn iter_demo() {
let v1 = vec![1, 2, 3];
let mut v1_iter = v1.iter();
// iter() returns an iterator of slices.
assert_eq!(v1_iter.next(), Some(&1));
assert_eq!(v1_iter.next(), Some(&2));
assert_eq!(v1_iter.next(), Some(&3));
assert_eq!(v1_iter.next(), None);
package com.github.philipjkim.demo.hexagonal
import ch.qos.logback.classic.Level
import ch.qos.logback.classic.Logger
import com.tngtech.archunit.core.importer.ClassFileImporter
import com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Nested
@philipjkim
philipjkim / FunctionalVsIemerativeTransformationTest.java
Created December 2, 2022 01:46
Java - Transformation from 2 arrays to a map - Imperative vs. Functional
import static org.junit.jupiter.api.Assertions.*;
class FunctionalVsIemerativeTransformationTest {
@Test
void functionalVersusImperative() {
// Imperative
var parameterNames = new String[]{"aaa", "bbb"};
var args = new Object[]{"arg1", "arg2"};
Map<String, Object> params1 = new HashMap<>();
@philipjkim
philipjkim / BST.java
Created December 13, 2016 05:17
Finding sum of n elements after kth smallest element in BST
package com.foo;
import java.util.Stack;
/*
Find sum of n elements after kth smallest element in BST.
Tree is very large, you are not allowed to traverse the tree.
*/
public class BST {
@philipjkim
philipjkim / elastic_aggregator.go
Last active June 16, 2021 18:02
Go Elasticsearch aggregation example
package main
import (
"fmt"
"time"
"encoding/json"
elastic "gopkg.in/olivere/elastic.v3"
)
@philipjkim
philipjkim / context_demo.go
Created April 24, 2019 06:02
Demo: Using context to cancel heavy jobs after timeout
package main
import (
"context"
"fmt"
"time"
)
// DemoTimeout .
func DemoTimeout(ctxTimeout time.Duration, workDuration time.Duration) error {
@philipjkim
philipjkim / git-amend-author.sh
Last active March 13, 2019 01:11
Bash scripts for amending author of commits at once
#!/bin/bash
# (for example, your previous author name contains `Anonymous`)
# @ PROJECT_ROOT dir: run
#
# git log | grep -B 1 "Anonymous" | grep commit | awk '{print $2}' | xargs -L 1 ./git-amend-author.sh
if [ "$#" -ne 1 ]; then
echo "Illegal number of parameters: $#"
exit 1
@philipjkim
philipjkim / vscode-user-settings.json
Created June 4, 2018 03:18
VS Code user settings
{
"editor.fontSize": 14,
"[go]": {},
"[python]": {
"editor.formatOnSave": true
},
"eslint.autoFixOnSave": true,
"eslint.validate": [
"javascript",
"javascriptreact",