Skip to content

Instantly share code, notes, and snippets.

View colus001's full-sized avatar

Seokjun Kim colus001

View GitHub Profile
@colus001
colus001 / ip.md
Created March 22, 2023 05:12
Simple IP Check
  • JSON

    $ curl ifconfig.co/json
    

    Response

    {
      "ip": "123.123.123.123",
    

"ip_decimal": 1234512345,

@colus001
colus001 / getMyIp.sh
Created February 26, 2020 02:29
Get current external ip address
$ curl ipinfo.io/ip
db.stats(1024 * 1024 * 1024)
interface State {
position: number;
}
function createDog() {
const state: State = {
position: 0,
};
return {
db.getCollection('summoners').aggregate([
{
$group: {
_id: { name: '$name' },
uniques: { $addToSet: "$_id" },
count: { $sum: 1 }
}
},
{
$match: {
@colus001
colus001 / useSafeState.ts
Last active August 29, 2019 09:22
Avoid memory leak when using React useState API with async function. Fix `Warning: Can't perform a React state update on an unmounted component.`
/**
* useSafeState
* - To avoid memory leak when setState called after unmounted
* @param defaultValue
*/
export function useSafeState<T>(defaultValue?: T): [T, React.Dispatch<React.SetStateAction<T>>] {
let isMounted = true;
React.useEffect(() => () => {
isMounted = false;
}, []);
@colus001
colus001 / measure-write-and-copy.js
Created January 22, 2019 03:01
Measure Node.js File IO in terms of copy and write
const fs = require('fs');
const path = require('path');
const rimraf = require('rimraf');
const ProgressBar = require('progress');
const readFrom = path.join(__dirname, './test.json');
const file = fs.readFileSync(readFrom);
const getRandomNumber = (number = 1000000) => Math.floor(Math.random() * number);
@colus001
colus001 / benchmark-for-immutable-array.md
Last active October 8, 2018 10:10
Quick benchmark for Immutable Array

Quick benchmark for merge two arrays with immutable state

CODE

var compare = () => {
  var a = _.range(0, 1000000)
  var b = _.range(1000000, 2000000)

  console.time('spread')
@colus001
colus001 / sha384.sh
Created July 9, 2018 06:54
sha384 for CSP
cat script.js | openssl dgst -sha384 -binary | openssl base64 -A
@colus001
colus001 / Math.sol
Last active July 2, 2018 14:49
Implemetation of JS Math.min and Math.max
pragma solidity ^0.4.23;
/**
* @title Math
* @dev Javascript Math.min and Math.max implementation
*/
library Math {
/**
* @dev Retreive smaller value from two parameters
*/