Skip to content

Instantly share code, notes, and snippets.

View lagagain's full-sized avatar

lagagain lagagain

View GitHub Profile
@lagagain
lagagain / maybe.js
Last active February 18, 2021 13:50
[javascript] Maybe / Box
function wrap(value){
switch(typeof value){
case 'number':
return new Number(value)
case 'string':
return new String(value)
case 'boolean':
return new Boolean(value)
case 'symbol':
@lagagain
lagagain / callme-1.js
Last active January 31, 2021 01:28
callme
call.exec = true;
call.toc = true;
call(callme, 1);
function callme(i) {
if (i < 0) return i;
console.log(i);
@lagagain
lagagain / readme.md
Last active February 7, 2021 22:39
var/let/global 變數差異

無關鍵字賦值、var宣告、let宣告最大的差別在於生存區域的不同。

無關鍵字賦值 這意味著全域變數的宣告,當然你在全域範圍使用var/let宣告也是全域的。只是無關鍵字可能引發意外的情況,像是你預期變數應該是函數區域的:

function printG(){
  g = 1
  console.log(`printG: `, g)
}
@lagagain
lagagain / .spacemacs
Last active January 2, 2021 06:06
spacemacs config
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
@lagagain
lagagain / ted_plugin.js
Created October 31, 2020 12:12
TED plugin
let block_keeper = document.querySelector("div.bg\\:white:nth-child(1) > div:nth-child(1) > div:nth-child(1)");
let video_region = block_keeper.firstChild;
block_keeper.style.height = "400px";
video_region.style.width = "700px";
video_region.style.position = "fixed";
video_region.style.zIndex = 1;
class Repeatable{
static RUN = 0;
static BREAK = -1;
static CONTINUE = 1;
constructor(env = {}){
this.i = 0;
this.env = env;
this._env = {...env};
this.status = Repeatable.RUN;
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const path = require('path');
const config = {
mode: 'development',
entry:{
index: "./src/index.js",
},
output:{
function on_back_click()
local str = tostring(input_number)
str = str:sub(0, str:len()-1)
input_number = tonumber(str)
if not input_number then input_number = 0 end
end
@lagagain
lagagain / main.c
Last active February 14, 2020 08:30
Some C(atexit and on_exit) and Assembly Examples
// about atexit and on_exit: https://www.gnu.org/software/libc/manual/html_node/Cleanups-on-Exit.html
#include <stdio.h>
void byebye();
void seeyouagain();
int main()
{
void *p = NULL;
atexit(byebye);
on_exit(seeyouagain, p);
@lagagain
lagagain / Proxy.py
Created January 2, 2020 04:28
Python Proxy
class Proxy:
__handler = None
def __init__(self, handler:object):
self.__handler = handler
@classmethod
def Cproxy(clz, opt:str, default_handler = None):
def _handler(self, *args, **kwargs):
handler = getattr(self.__handler, opt, default_handler if default_handler else clz.__defaultOpt)
return handler(*args, **kwargs)
return _handler