Skip to content

Instantly share code, notes, and snippets.

@albert-zhang
albert-zhang / change-chrome-ua.js
Created March 14, 2023 00:26
modify the UA of chrome
var actualCode = '(' + function() {
'use strict';
var navigator = window.navigator;
var modifiedNavigator;
if ('userAgent' in Navigator.prototype) {
// Chrome 43+ moved all properties from navigator to the prototype,
// so we have to modify the prototype instead of navigator.
modifiedNavigator = Navigator.prototype;
} else {
@albert-zhang
albert-zhang / what-forces-layout.md
Created November 25, 2021 02:17 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@albert-zhang
albert-zhang / Apple_mobile_device_types.txt
Created November 22, 2021 08:31 — forked from adamawolf/Apple_mobile_device_types.txt
List of Apple's mobile device codes types a.k.a. machine ids (e.g. `iPhone1,1`, `Watch1,1`, etc.) and their matching product names
i386 : iPhone Simulator
x86_64 : iPhone Simulator
arm64 : iPhone Simulator
iPhone1,1 : iPhone
iPhone1,2 : iPhone 3G
iPhone2,1 : iPhone 3GS
iPhone3,1 : iPhone 4
iPhone3,2 : iPhone 4 GSM Rev A
iPhone3,3 : iPhone 4 CDMA
iPhone4,1 : iPhone 4S
@albert-zhang
albert-zhang / upstart.md
Created February 13, 2019 10:09
upstart

create file the-name.service at /etc/systemd/system:

[Unit]
Description=the-desc
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
@albert-zhang
albert-zhang / another.sh
Last active December 3, 2018 01:59 — forked from jobsamuel/readme.md
Run NodeJS as a Service on Ubuntu 14.04 LTS
start on filesystem and started networking
respawn
chdir /home/work/node-app
env NODE_ENV=production
exec /usr/bin/node /home/work/node-app/index.js
@albert-zhang
albert-zhang / gem_install_to_usr.sh
Created August 16, 2018 02:53
gem_install_to_usr.sh
# ref: https://stackoverflow.com/questions/31972968/cant-install-gems-on-os-x-el-capitan
sudo gem install THE_GEM -n/usr/local/bin
@albert-zhang
albert-zhang / check-repo-version.js
Created August 14, 2018 23:49
check-repo-version.js
const semver = require('semver')
const exec = require('child_process').exec
const packageJson = require('./package.json')
const prjName = packageJson.name
function getRemoteVer() {
return new Promise((resolve, reject) => {
const theCmd = 'npm show ' + prjName + ' version --registry=http://example.com'
exec(theCmd, function(err, stdout, stderr) {
@albert-zhang
albert-zhang / angularjs.js
Last active August 10, 2018 03:15
angularjs
// Get provider outside of angular:
angular.element(document.querySelector('.app')).injector().get('SomeService')