Skip to content

Instantly share code, notes, and snippets.

View tshu-w's full-sized avatar
🤯
Exploring

Tianshu Wang tshu-w

🤯
Exploring
View GitHub Profile
@tshu-w
tshu-w / Meisell-Lehmer.cpp
Created October 12, 2016 09:57
calculate the prime number lower and equal than n quickly.
#include<bits/stdc++>
/Meisell-Lehmer
const int MAX_N = 5e6 + 2;
bool np[MAX_N];
int prime[MAX_N], pi[MAX_N];
int getprime()
{
int cnt = 0;
np[0] = np[1] = true;
pi[0] = pi[1] = 0;
@tshu-w
tshu-w / stlib.cpp
Created December 15, 2016 03:19
ACM/ICPC header
#include <bits/stdc++.h>
#define IOS std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr);
// #define __DEBUG__
#ifdef __DEBUG__
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif
#define filename ""
@tshu-w
tshu-w / save_safari_tabs.scpt
Last active February 3, 2023 03:24
Save all safari tabs in a single file and reopen them with a double click.
-- Detect if the Safari window exists
tell application "System Events"
if not (exists (front window of process "Safari")) then
return
end if
end tell
-- Assume the frontmost Finder window (or the Desktop)
-- is where we want to store the script.
try
@tshu-w
tshu-w / stdc++.h
Created January 22, 2018 09:12
Linux GCC 4.8.0 /bits/stdc++.h header definition.
// C++ includes used for precompiling -*- C++ -*-
// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library 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 3, or (at your option)
// any later version.
@tshu-w
tshu-w / SpaceFn.json
Last active May 10, 2024 05:50
Karabiner Elements config to simulate SpaceLauncher (https://ke-complex-modifications.pqrs.org/?q=spacefn%20plus)
{
"title": "SpaceFN",
"rules": [
{
"description": "SpaceFN: Space enables SpaceFN mode (see: https://geekhack.org/index.php?topic=51069.0 & https://spacelauncherapp.com)",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "spacebar"
@tshu-w
tshu-w / huxiu.js
Last active October 22, 2019 13:34
Redirect m.huxiu.com to www.huxiu.com by Tampermokey
// ==UserScript==
// @name Redirect Huxiu Mobile Link
// @namespace https://gist.github.com/TshuW/136f461b93dc258f6322b496fd656717
// @version 0.1
// @description Redirect m.huxiu.com to www.huxiu.com
// @author Tshu Wang
// @match m.huxiu.com/article/*
// @grant none
// ==/UserScript==
@tshu-w
tshu-w / lang-org.el
Last active January 12, 2021 13:34
Emacs Org Capture or Agenda in a new Frame and quit after finishing.
;;; System interaction function
(defun supress-frame-splitting (&rest r)
(let ((frame-name (frame-parameter nil 'name)))
(when (or (equal "capture" frame-name)
(equal "agenda" frame-name))
(delete-other-windows))))
(defun org-capture-finalize@after (&rest r)
(when (equal "l" (plist-get org-capture-plist :key))
(run-at-time 0 nil #'osx-switch-back-to-previous-application))
@tshu-w
tshu-w / arXiv_titlatorizer.js
Last active January 16, 2021 08:15
arXiv title fixer
// ==UserScript==
// @name Arxiv titlatorizer
// @namespace Titlatorizer
// @version 0.1
// @description Set correct tab <title> on arXiv pages.
// @author Tianshu Wang
// @match https://arxiv.org/pdf/*
// @grant GM_xmlhttpRequest
// ==/UserScript==
//
@tshu-w
tshu-w / config.js
Last active June 7, 2022 05:37
Surfingkeys Settings
settings.scrollStepSize = 100
settings.focusAfterClosed = "last"
settings.hintAlign = "left"
@tshu-w
tshu-w / EmacsClient.scpt
Created August 8, 2022 08:16
EmacsClient.app on macOS
on open location address
if {address starts with "org-protocol"} then
do shell script "zsh -c 'ec \"" & address & "\"'"
else
do shell script "zsh -c 'ec --eval '\"'\"'(browse-url \"" & address & "\")'\"'\"''"
end if
end open location
on open filenames
set args to ""