Skip to content

Instantly share code, notes, and snippets.

View CMCDragonkai's full-sized avatar
🚀
Lightspeed

CMCDragonkai

🚀
Lightspeed
View GitHub Profile
@CMCDragonkai
CMCDragonkai / Derivation.md
Last active January 1, 2021 06:20
Combine Discounts #python

How to Combine Discounts

Suppose you have $1000 dollars, and you are applying 40% discount first, then 42% discount second.

What is the total discount?

1000 - 0.4*1000 - (0.42 * (1000 - 0.4*1000)) = 348
I - D1*I - (D2 * (I - D2*I)) = O
I - D1*I - D2*I + D1*D2*I = O
@CMCDragonkai
CMCDragonkai / Ref.vue
Last active August 27, 2021 08:48
Vue 3 Reactivity #vue
<template>
<button @click="counter += 1">{{ counter }}</button>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue';
export default defineComponent({
setup () {
// by using ref, the counter becomes a proxy
@CMCDragonkai
CMCDragonkai / update_master.sh
Created December 22, 2020 00:54
Rebasing a Feature Branch on Master Branch without Switching Branches #git
#!/usr/bin/env sh
git fetch origin master:master
@CMCDragonkai
CMCDragonkai / new_disk_zfs_raid_0.md
Last active March 31, 2024 08:32
Adding a new disk ZFS RAID-0 #zfs

Adding a new disk ZFS RAID-0

When adding a new disk to ZFS RAID-0, you must ensure that the disk has the same storage size as the other disks.

You will need the gptfdisk package to use sgdisk.

hdd='/dev/disk/by-id/<DISKNAME>'
zpool labelclear -f "$hdd" || true
sgdisk --zap-all "$hdd"
@CMCDragonkai
CMCDragonkai / function_type_signature_declarations_in_typescript.ts
Last active December 10, 2020 03:14
Function Type Signature Declarations in TypeScript #typescript
// there are several ways to declare function types
// these are "first-order" functions
// normal function declaration
function f1 (i: number): number {
return i + 1;
}
// this relies on inference
const f2 = (i: number) => i + 1;
@CMCDragonkai
CMCDragonkai / machine.js
Last active October 21, 2020 06:45
Backup Restore Machine
const canBackup = (context, event) => {
return !context.backupLock
};
const canRestore = (context, event) => {
return !context.restoreLock
};
const backupMachine = Machine(
{
@CMCDragonkai
CMCDragonkai / sqlparams.py
Last active September 23, 2020 05:11
Dynamic Binding for PostgreSQL with AsyncPG #python #postgresql #asyncpg
from collections import OrderdDict
from typings import Hashable, List
class SQLParams:
def __init__(self):
self.__values = OrderedDict()
self.__count = 1
@CMCDragonkai
CMCDragonkai / labelencoder_onehotencoder.py
Created July 7, 2020 06:52
LabelEncoder and OneHotEncoder #python #sklearn
import numpy as np
import pandas as pd
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
classes_df = pd.DataFrame({
"class_id": ['n01669191', 'n01812337', 'n02007558', 'n02871439', 'n04306847',
'n10226413', 'n10267311', 'n12360108', 'n12662772', 'n13918274']
})
@CMCDragonkai
CMCDragonkai / batch_size_image_size.md
Created July 3, 2020 13:18
Batch size and Image size optimisation for CNNs

Batch size and Image size optimisation for CNNs

Given an initial size of an image. If we drop the square image size by side_p percentage points.

How much does the area percentage drop by?

The formula is as below:

area_p = [side_p * x^2 * (2 - side_p)] / 100