Skip to content

Instantly share code, notes, and snippets.

View zetavg's full-sized avatar

Pokai Chang zetavg

View GitHub Profile
@zetavg
zetavg / README.md
Created October 10, 2022 04:18
Apple Shortcut for creating a long-term (per day) stock chart that can be used as a widget with Charty.

Apple Shortcut: Long-term Stock Chart with Charty

Apple Shortcut for creating a long-term (per day) stock chart that can be used as a widget with Charty.

Requirements

@zetavg
zetavg / install-openjdk.sh
Created November 5, 2021 16:51
Install OpenJDK on macOS
brew install openjdk && echo 'export PATH="$(brew --prefix openjdk)/bin:$PATH"' >> ~/.zshrc
if application "Spotify" is running then
using terms from application "Spotify"
if player state of application "Spotify" is paused then
tell application "Spotify" to play
else
tell application "Spotify" to pause
end if
end using terms from
else
using terms from application "Music"
@zetavg
zetavg / firstrade-to-yahoo-finance-import.js
Last active October 10, 2022 04:25
Script to import Firstrade positions into Yahoo Finance as Portfolio.
/*
* 1. Sign in to Firstrade's positions page (https://invest.firstrade.com/cgi-bin/main#/cgi-bin/acctpositions).
* 2. Open DevTools (Command + Option + i) JS console (Esc), paste the code below. Then stuff will be copied.
* 3. Open a new text file, paste the copied content into it and save it as *.csv.
* 4. Go to the Portfolios page on Yahoo Finance (https://finance.yahoo.com/portfolios), click "Import" and upload the file created on step 3.
* 5. You now have a new portfolio imported from your Firstrade positions data (you might want to rename it).
*/
function getPositionTable() {
async function lookup(word, dictionaryCode = 'american-english', accessKey = window.ACCESS_KEY) {
const response = await fetch(
`https://dictionary.cambridge.org/api/v1/dictionaries/${dictionaryCode}/search/first/?q=${word}&format=xml`,
{
method: 'GET',
headers: { accessKey },
}
);
const json = await response.json();
const parser = new DOMParser();
@zetavg
zetavg / lingvist-scripts.js
Created July 20, 2021 16:32
Some JavaScript script for Lingvist.
function delay(ms = 1000) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
function getCourseIdFromPath() {
try {
const [, id] = window.location.hash.match(/course-wizard\/edit\/([^/]+)/);
return id;
@zetavg
zetavg / copy-gandankit-menu-items.js
Last active May 12, 2020 08:43
需要注意有些 menu item 是被列在「前一天預定」section 裡,可能要把最後那些挑掉。善用 Paste values only 來貼。
function getGanDanKitMenuItems() {
return Array.from(document.querySelectorAll('.promain'))
.map(e => ({
name: e.querySelector('h3').innerText.replace(/(/g, ' (').replace(/)/g, ')'),
price: parseInt(e.querySelector('em').innerText.replace(/[^0-9]/mg, '')),
}))
// Filter out duplicated items
.filter((v, i, arr) => (arr.findIndex(a => a.name === v.name) === i))
}
function copyUberEatsMenuItems() {
const items = getUberEatsMenuItems()
copy(
items
.map(i => `${i.name}\t${i.price}`)
.join('\n')
)
}
function getUberEatsMenuItems() {
@zetavg
zetavg / rails.log
Created April 3, 2020 17:45
Rails, Passenger, Nginx, Nix: uninitialized constant Bundler::Settings (NameError)
Error: The application encountered the following error: uninitialized constant Bundler::Settings (NameError)
/nix/store/li2vmpp6mxqzrs6s95szj1xga380hsv4-sample-rails-app-dev-bundler-env/lib/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/settings.rb:6:in `<module:Bundler>'
/nix/store/li2vmpp6mxqzrs6s95szj1xga380hsv4-sample-rails-app-dev-bundler-env/lib/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler/settings.rb:5:in `<top (required)>'
/nix/store/928i2cf1wizgm7dapmnk0m8ijrsjdj43-ruby-2.5.7/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:72:in `require'
/nix/store/928i2cf1wizgm7dapmnk0m8ijrsjdj43-ruby-2.5.7/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:72:in `require'
/nix/store/li2vmpp6mxqzrs6s95szj1xga380hsv4-sample-rails-app-dev-bundler-env/lib/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler.rb:273:in `settings'
/nix/store/li2vmpp6mxqzrs6s95szj1xga380hsv4-sample-rails-app-dev-bundler-env/lib/ruby/gems/2.5.0/gems/bundler-1.17.3/lib/bundler.rb:84:in `configured_bundle_path'
@zetavg
zetavg / machine.js
Created December 25, 2019 09:55
Generated by XState Viz: https://xstate.js.org/viz
const appMachine = Machine({
id: 'app',
initial: 'unauthenticated',
states: {
unauthenticated: {
on: {
LOGIN: 'authenticated',
},
},
authenticated: {