Skip to content

Instantly share code, notes, and snippets.

View nbdd0121's full-sized avatar

Gary Guo nbdd0121

View GitHub Profile
@nbdd0121
nbdd0121 / Makefile
Last active February 9, 2022 16:49
Archive member selection
run: main
./main
a.o: a.c
gcc $^ -c -o $@
b.o: b.c
gcc $^ -c -o $@
foo.a: a.o b.o
@nbdd0121
nbdd0121 / stop-leak.ps1
Created September 28, 2021 20:28
"Stop" DWM from leaking memory
Get-Process | Where-Object {($_.Name -eq 'dwm' -and $_.PagedMemorySize64 -gt 2147483648) -or ($_.Name -eq 'YourPhoneServer' -and $_.PagedMemorySize64 -gt 1073741824)} | ForEach-Object {$_.Kill()}
impl Solution {
pub fn word_break(s: String, word_dict: Vec<String>) -> Vec<String> {
fn helper<'a>(
answer: &mut Vec<String>,
current: &mut Vec<&'a str>,
str: &str,
dict: &'a [String],
) {
if str.is_empty() {
answer.push(current.join(" "));
@nbdd0121
nbdd0121 / timezone.js
Created September 28, 2018 21:55
Bilibili Timeline Timezone Fix
let timezoneOffset = 8 * 60; // in minutes
function timeshift(date) {
return new Date(+date + timezoneOffset * 60000);
}
// Seconds and Milliseconds are always same as timezone offset is always multiple of 0.5
for (let name of ['Date', 'Day', 'FullYear', 'Hours', 'Minutes', 'Month']) {
Date.prototype['get' + name] = function () {
return timeshift(this)['getUTC' + name]();
@nbdd0121
nbdd0121 / shadowdom-css.js
Created August 9, 2015 12:53
A CSS encapsulation polyfill that works on top of WebComponents.js
/*
* Copyright (c) 2015, Gary Guo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
@nbdd0121
nbdd0121 / promise.cc
Created April 29, 2015 11:29
C++ Promise via Coroutine
#include <functional>
#include <cstdio>
#include <vector>
#include <queue>
#include <memory>
#include "Coroutine.h"
using norlit::coroutine::Coroutine;
#include <iostream>
#include <vector>
int main(){
int length;
std::cin >> length;
int* data = new int[length];
for(int i=0;i<length;i++){
std::cin >> data[i];
}
@nbdd0121
nbdd0121 / bf-nlir-asm.asm
Created March 12, 2015 13:09
Brainf*ck Norlit IR Compiled to Assembly
[bits 64]
[global norlit.lib.zeroinitialize]
[extern memset]
norlit.lib.zeroinitialize:
mov r8, rdx
mov rdx, 0
jmp memset
[extern putchar]
[extern getchar]
[global main]
@nbdd0121
nbdd0121 / 24-points-ver1.js
Last active August 29, 2015 14:14
24-points javascript calculator unoptimized / no parenthesis removal / only single answer is shown
function wrap(num) {
return ' ' + num + ' ';
}
function singleStep(ans, a, b, arr, i, target, sym) {
arr[i] = ans;
return (target = calc24(arr, target)) &&
target.replace(wrap(ans), '(' + wrap(a) + sym + wrap(b) + ')');
}
@nbdd0121
nbdd0121 / apt-cyg
Created February 6, 2015 09:19
apt-cyg for Chinese users
#!/bin/bash
# vim: set ts=2 sw=2 tw=0 et :
#
# apt-cyg: install tool for cygwin similar to debian apt-get
#
# Copyright (C) 2005-9, Stephen Jungels
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2