Skip to content

Instantly share code, notes, and snippets.

View mnikn's full-sized avatar
🕳️
Strike the earth

mnikn mnikn

🕳️
Strike the earth
  • earth
View GitHub Profile
import dayjs, { Dayjs } from 'dayjs';
import { get } from 'lodash';
type FormatOptions = {
reliable: boolean;
};
type BaseSchemaField = {
type: SchemaFieldType;
source?: ((parentSourceData: any, rootSourceData: any) => any) | string;
@mnikn
mnikn / Array.gd
Last active May 29, 2022 08:00
godot utils
extends Node
class_name ArrayUtils
static func filter(arr: Array, prop: Dictionary) -> Array:
var res = []
for item in arr:
for key in prop.keys():
if prop[key] is Array and item[key] in prop[key]:
res.push_back(item)
elif (!prop[key] is Array) and prop[key] == item[key]:
@mnikn
mnikn / shader-utils
Last active June 24, 2022 03:44
shader-utils
float rect(vec2 uv, vec2 size) {
float blur = 0.000;
// 让 size 成正比
size = 0.5 - size * 0.5;
// 先画一边
vec2 r = vec2(step(size.x, uv.x), step(size.y, uv.y));
// 再画相反的边,相乘得出相交位置就是对应的矩形
r *= vec2(step(size.x, 1.0 - uv.x), step(size.y, 1.0 - uv.y));
// x 和 y 相乘得出矩形的像素点值
return r.x * r.y;
@mnikn
mnikn / pico8_utils.lua
Last active January 4, 2022 09:48
pico-8 utils
function wrap_text(content,max_count)
local lines={''}local wcount=0
for i=1,#content do
local c=sub(content,i,i)
lines[#lines]..=c
wcount+=1
if (wcount>=max_count)
then
wcount=0
lines[#lines]..='\n'
@mnikn
mnikn / editorconfig
Created August 27, 2019 23:35
[editorconifg]
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2
[Makefile]
indent_style = tab
@mnikn
mnikn / ctags
Last active August 26, 2019 14:42
[ctags]
--recurse=yes
--tag-relative=yes
--exclude=tags
--exclude=TAGS
--exclude=GTAGS
--exclude=GPATH
--exclude=*node_modules*
--exclude=*.git*
@mnikn
mnikn / search.js
Last active June 19, 2019 07:09
[search] search algorithm #algorithm
function binarySearch(nums, target) {
let i = 0, j = nums.length - 1;
while (i <= j) {
const mid = (i + j) >> 1;
if (nums[mid] === target) return mid;
else if (nums[mid] > target) j = mid;
else i = mid + 1;
}
return -1;
}
@mnikn
mnikn / router.js
Last active April 18, 2020 05:19
[router] a simple web router #utils
// the router should be sigleton
class Router {
constructor(routeMap) {
this._routeMap = routeMap;
this.bindEvent();
}
init(url) {
let fn = this._routeMap[url];
window.history.replaceState({url: url}, '', url);
@mnikn
mnikn / debounce.js
Created February 27, 2019 01:48
[debounce] debounce and throttle #utils
function debounce(fn, delay) {
let timer = setTimeout(fn, delay);
return function(){
clearTimeout(timer);
fn.apply(this, arguments);
};
}
function throttle(fn, delay) {
let timer = setTimeout(fn, delay);
@mnikn
mnikn / array.js
Last active September 30, 2023 03:17
[array] array utils #utils
function duplicate(arr){
let set = new Set();
let result = [];
for(let i = 0;i < arr.length; ++i) {
if(!set.has(arr[i])) result.push(arr[i]);
set.add(arr[i]);
}
return result;
}