Skip to content

Instantly share code, notes, and snippets.

View bidiu's full-sized avatar

Henry bidiu

  • Archon Systems Inc.
  • Toronto, ON
  • 01:18 (UTC -04:00)
View GitHub Profile
@bidiu
bidiu / full-page-screenshots-selenium-chrome.rb
Created March 2, 2017 02:39 — forked from elcamino/full-page-screenshots-selenium-chrome.rb
How to take full-page screenshots with Selenium and Google Chrome in Ruby
#!/usr/bin/env ruby
require 'selenium-webdriver'
wd = Selenium::WebDriver.for :remote, url: 'http://10.3.1.7:4444/wd/hub', desired_capabilities: :chrome
wd.navigate.to 'https://snipt.net/restrada/python-selenium-workaround-for-full-page-screenshot-using-chromedriver-2x/'
# Get the actual page dimensions using javascript
#
width = wd.execute_script("return Math.max(document.body.scrollWidth, document.body.offsetWidth, document.documentElement.clientWidth, document.documentElement.scrollWidth, document.documentElement.offsetWidth);")
@bidiu
bidiu / introrx.md
Created May 18, 2017 20:39 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
const fs = require('fs');
const readline = require('readline');
const FILE_PATH = './src/app/assets/css/phillip/styles.css';
const OUTPUT_PATH = './src/app/assets/css/phillip/styles.css';
const NEW_LINE = '\n';
const lineReader = readline.createInterface({
input: fs.createReadStream(FILE_PATH)
});
const path = require('path');
const fs = require('fs');
const readline = require('readline');
const ROOT = './src/app/assets/css';
const FILE_NAME = 'styles.css';
const EXCLUDES = [
'bloomberg', 'example_dark', 'merrilledge_blue', 'merrilledge_dark', 'merrilledge_light', 'trademonster_dark', 'schwab_dark'
];
const NEW_LINE = '\n';
const { exec } = require('child_process');
module.exports = function execCmd(cmd, { fromDir = '.' } = {}) {
return new Promise((resolve, reject) => {
exec(`cd ${fromDir} & ${cmd}`, (error, stdout, stderr) => {
if (!error) {
resolve(stdout);
} else {
reject({ error: error, stderr: stderr });
}
@bidiu
bidiu / regex-match-last-word-of-url.md
Last active November 1, 2017 02:26
Regex matching last word of a url
@bidiu
bidiu / note-on-osx-pingfang.md
Created January 3, 2018 14:43 — forked from bitinn/note-on-osx-pingfang.md
A few notes on using OS X 10.11 (El Capitan)'s new Chinese font: PingFang (苹方/萍方).

What's this about?

OS X 10.11, aka El Capitan, comes with a new system font for Chinese users, named PingFang, it includes 6 weights for both Simplified and Traditional Chinese. The same font also appear on iOS 9 as the default UI font, though Apple didn't mention it explicitly.

How to get it?

If you are in Apple Developer Program (costs 99 USD a year), then you can get them now at their developer resource site, otherwise you can wait for their public beta to come out in July or wait for the public release this fall (a free upgrade like previous release).

Or you can get PingFang.ttc from your developer friends, though you are probably violating its font license one way or another, but I am not a lawyer so freedom to you.

@bidiu
bidiu / es-backup.py
Last active February 21, 2018 04:48
Back up Elasticsearch indices.
import time
import datetime
from elasticsearch import Elasticsearch, helpers
# the underlying Elasticsearch client
es = Elasticsearch(['localhost:9200'],
sniff_onz_start=True,
sniff_on_connection_fail=True,
sniffer_timeout=60)
const { execSync } = require('child_process');
const path = require('path');
const fs = require('fs');
const SVN_DIR_PATH = path.join(__dirname, '..', 'svn');
if (!fs.existsSync(SVN_DIR_PATH)) {
fs.mkdirSync(SVN_DIR_PATH);
}

ETags: a pretty sweet feature of HTTP 1.1

HTTP caching review

HTTP provides two ways for servers to control client-side caching of page components:

  • freshness may be based on a date or a token whose meaning is app-specific
  • whether or not the client needs to confirm the cached version is up-to-date with the server

This breaks down as follows:

  • Cache locally and don't check before using.