Skip to content

Instantly share code, notes, and snippets.

@pallove
pallove / isProxy.js
Created December 10, 2023 06:47
check whether javascript object is a proxy
const isProxy = obj => {
try {
let test = {obj : true}
test[obj] = false
} catch {
return true
}
return false
}
@pallove
pallove / Token.sol
Created March 2, 2022 01:12
a solidity ERC20 smart contract with fees (marking, burn, ect)
/**
* Submitted for verification at BscScan.com on 2022-02-24
*/
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
@pallove
pallove / Fn_keys_for_app.lua
Last active January 4, 2022 01:02
because the vscode use Fn keys(debug, rename, Go to...), and the karabiner is so heavy, so i do some work on Hammerspoon.
--- place the snippets in your ~/.hammerspoon/init.lua
local sys_key = {
[3] = {pos = 1, key = 'F1'}, -- BRIGHTNESS_DOWN
[2] = {pos = 2, key = 'F2'}, -- BRIGHTNESS_UP
[22] = {pos = 5, key = 'F5'}, -- ILLUMINATION_DOWN
[21] = {pos = 6, key = 'F6'}, -- ILLUMINATION_UP
[20] = {pos = 7, key = 'F7'}, -- REWIND
[16] = {pos = 8, key = 'F8'}, -- PLAY
[14] = {pos = 9, key = 'F9'}, -- FAST
@pallove
pallove / poemnet-workflow.go
Created November 21, 2021 11:29
an alfredworkflow suggestion about gushiwen.cn
package main
import (
"encoding/json"
"fmt"
"html"
"log"
"net/http"
"os"
"strings"
@pallove
pallove / HoldToQuit.spoon.lua
Last active May 24, 2022 14:42
improve the spoon(HoldToQuit) of hammerspoon, the behaviour like Google Chrome`s
--- === HoldToQuit ===
---
--- Instead of pressing ⌘Q, hold ⌘Q to close applications.
local obj = {}
obj.__index = obj
-- Metadata
obj.name = "HoldToQuit"
obj.version = "1.1"
@pallove
pallove / scand.go
Last active November 9, 2018 03:31
walk directory with filetype filter
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"strings"
)
@pallove
pallove / TimerEx.ts
Created September 29, 2018 07:40
a timer class withe TypeScript
export interface TimerObj {
id : number;
func : (...params) => void;
interval : number;
loop : number;
forever : boolean;
params : Array<any>;
count : number;
finished : boolean;
call_time : number;
@pallove
pallove / fit_number.lua
Last active September 21, 2018 11:16
随机填充25个数到9*9格子,并且保证每行不少于一个数
local function gen()
local arr = {}
for i = 1, 9 * 9 do
arr[i] = i > 25 and 0 or i
end
return arr
end
local function pr(arr)
local r = {}
@pallove
pallove / my_free.c
Created September 13, 2017 03:59
safe malloc and free with tag
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAGIC_TAG 0x11223344
inline static void* my_malloc(int size) {
void* ptr = malloc(size + sizeof(MAGIC_TAG));
int *p = (int *) ptr;
*p = MAGIC_TAG;
@pallove
pallove / minstack.c
Last active April 27, 2017 13:06
min value get in stack
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct tval {
int v;
int i;
};
struct minstack {