Skip to content

Instantly share code, notes, and snippets.

View i10416's full-sized avatar
πŸ™ƒ

110416 i10416

πŸ™ƒ
View GitHub Profile
@i10416
i10416 / gcd.sc
Last active July 5, 2021 06:50
gcd implementation in scala script
// scala 2.13.6
// ammonite 2.4.0
import scala.math.Integral
import scala.math.{BigDecimal,BigInt}
object NumericUtil {
def gcd[T :Integral](a:T,b:T):T = {
if(b == 0){
a
@i10416
i10416 / gcd_and_lcm.sc
Created July 5, 2021 07:21
gcd and lcm implementation in scala script
// scala 2.13.6
// ammonite 2.4.0
import scala.math.Integral
import scala.math.{ BigDecimal, BigInt }
object NumericUtil {
def gcd[T: Integral](a: T, b: T): T = {
if (b == 0) {
a
@i10416
i10416 / bubble_sort.sc
Created July 5, 2021 08:03
recursive bubble sort implementation in scala script
// scala 2.13.6
// ammonite 2.4.0
def bubbleSort[T: Ordering](orderables: Seq[T]): Seq[T] = {
swapRec(orderables).splitAt(orderables.length - 1) match {
case (Nil, Nil) => Nil
case (Nil, head) => head
case (head, last) => bubbleSort(head) ++ last
}
}
@i10416
i10416 / cat_snippets.sc
Created July 5, 2021 08:58
parallel IO cats snippets in scala script
// scala 2.13.6
// ammonite 2.4.0
import $ivy.`org.typelevel::cats-effect:3.1.1`
import $ivy.`org.typelevel::cats-core:2.2.0`
import cats.effect.IO
import cats.syntax.apply._
import cats.syntax._
import scala.concurrent.duration._
import cats.effect.unsafe.implicits.global
@i10416
i10416 / heroku_cli_public_key_not_available_workaround.txt
Created July 5, 2021 12:01
how to solve the gpg error: public key unavailable when running apt update
curl https://cli-assets.heroku.com/apt/release.key | sudo apt-key add -
sudo apt update
@i10416
i10416 / leetcode_easy_solutions.sc
Created July 5, 2021 13:14
leetcode easy solutions
import java.util.Stack
import java.util.Deque
import scala.collection.mutable.ArrayDeque
// scala 2.13.6
// ammonite 2.4.0
def hammingDistance(one: Int, another: Int): Int = {
// note: xor で η•°γͺγ‚‹θ€…εŒε£«γ γ‘γƒ•γƒ©γ‚°γŒη«‹γ€
(one ^ another).toBinaryString.count { s => s == '1' }
}
@i10416
i10416 / tuple_flatten.scala
Last active July 6, 2021 12:28
extension to flatten nested tuple in scala 3
extension[T<:Tuple] (i:T) {
def flatten = flattenTuple(i)
private def flattenTuple[A <: Tuple](tuple: A): FlattenTypeOf[A] = {
val flatten = tuple match {
case h *: remains =>
h match {
case subtpl: Tuple => flattenTuple(subtpl) ++ flattenTuple(remains)
case _ => h *: flattenTuple(remains)
}
@i10416
i10416 / jwm_bug_on_windows.java
Created August 24, 2021 11:36
window crashes when no animation is running in the current window.
package org.jetbrains.jwm.examples;
import org.jetbrains.jwm.*;
import org.jetbrains.skija.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.stream.*;
import java.io.File;
HMODULE hUser = GetModuleHandleA("user32.dll");
if (hUser)
{
pfnSetWindowCompositionAttribute setWindowCompositionAttribute = (pfnSetWindowCompositionAttribute)GetProcAddress(hUser, "SetWindowCompositionAttribute");
if (setWindowCompositionAttribute)
{
ACCENT_POLICY accent = { ACCENT_ENABLE_BLURBEHIND, 0, 0, 0 };
WINDOWCOMPOSITIONATTRIBDATA data;
data.Attrib = WCA_ACCENT_POLICY;
data.pvData = &accent;
@i10416
i10416 / shapeless.worksheet.sc
Created December 23, 2021 06:02
generic vector representation using shapeless
import $ivy.`com.chuusai::shapeless:2.3.7`
import shapeless._
trait VecLike[T]{
def dim:Int
def add(a:T,b:T):T
def sub(a:T,b:T):T
}
implicit def doubleVec2D:VecLike[(Double,Double)] =
new VecLike[(Double,Double)] {