Skip to content

Instantly share code, notes, and snippets.

View futurist's full-sized avatar

James Yang futurist

  • China
View GitHub Profile
@futurist
futurist / cssobj-plugin-keyframes.js
Created November 11, 2016 11:35
cssobj-plugin-keyframes.js
const random = +new Date()
export default {
selector: function(sel) {
let match = /^\s*@keyframes (.*)$/i.exec(sel)
return match ? '@keyframes ' + match[1].trim() + random : sel
},
value: function(val, key) {
return key=='animateName' ? val + random : val
}
}
@futurist
futurist / battery-check.sh
Created November 16, 2016 08:48
Sleep when battery below 20% in MacBook
#!/bin/sh
MODE=`/usr/bin/pmset -g | awk '/hibernatemode/ { print $2 }'`
LEFT=`/usr/bin/pmset -g batt | grep Internal | awk '{ print $2 }' | awk -F % '{ print $1 }'`
if [ $LEFT -lt 30 ] && [ $MODE != 3 ] ; then
{
/usr/bin/logger -t "hibernatemode" "Battery level less than 30%; setting hibernatemode to 3"
/usr/bin/pmset -a hibernatemode 3
}
elif [ $LEFT -gt 50 ] && [ $MODE != 0 ]; then
@futurist
futurist / git-alias.sh
Created November 18, 2016 01:12
alias for git
# alias for git
alias ga='git add'
alias ga.='git add .'
alias gaa='git add -A'
alias gs='git status'
alias gp='git push'
alias gm='git commit'
alias gmm='git commit -m'
alias gl='git log --all --decorate --graph'
@futurist
futurist / get-finder-path.scpt
Created November 18, 2016 09:21
Get finder selection path and save to clipboard, on macOS
# activate application "Finder"
set l to {}
tell application "Finder" to repeat with f in (get selection)
set end of l to POSIX path of (f as alias)
end repeat
set text item delimiters to linefeed
set the clipboard to (l as text)
@futurist
futurist / ec.scpt
Created November 18, 2016 09:32
Put current Finder items to Eamcs in macOS
# activate application "Finder"
tell application "Finder" to repeat with f in (get selection)
set p to POSIX path of (f as alias)
do shell script "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -n -f '/tmp/emacsserver/server' " & quoted form of p
end repeat

What is Critical Rendering Path

The Critical Rendering Path is the sequence of steps the browser goes through to convert the HTML, CSS and JavaScript into actual pixels on the screen. If we can optimize the critical rendering path, we can make our pages faster.

Constructing the DOM

When you type an URL and hit enter, the browser sends a request to the server. The server returns a response with the HTML to the browser, which somehow needs to convert the markup into something that we can see on the screen.

The browser follows a well defined set of steps and it all starts with processing the HTML and building the DOM.

@futurist
futurist / bongo.sh
Created February 10, 2017 10:08 — forked from smashew/bongo.sh
This one works... Tested
LOADING=false
usage()
{
cat << EOF
usage: $0 [options] dbname
OPTIONS:
-h Show this help.
-l Load instead of export
@futurist
futurist / bongo.sh
Last active February 11, 2018 14:56 — forked from nhoening/bongo.sh
Allowing to pass a query for exporting specific data. Added a LIMIT option to limit the number of returned results. Added a debug switch to see errors.
#!/bin/bash
LOADING=false
DEBUG=/dev/null
usage()
{
cat << EOF
usage: $0 [options] <DBNAME>
@futurist
futurist / back_forward.js
Created March 2, 2017 12:25 — forked from sstephenson/back_forward.js
How to detect whether a hash change came from the Back or Forward button
var detectBackOrForward = function(onBack, onForward) {
hashHistory = [window.location.hash];
historyLength = window.history.length;
return function() {
var hash = window.location.hash, length = window.history.length;
if (hashHistory.length && historyLength == length) {
if (hashHistory[hashHistory.length - 2] == hash) {
hashHistory = hashHistory.slice(0, -1);
onBack();
@futurist
futurist / gist:0ba49fe408f6d345e220421e6d24955e
Last active March 13, 2017 03:12
Remove Sendmail from Ubuntu

Remove Sendmail from Ubuntu

This should help you completely uninstall Sendmail and all that comes with it.

First, stop the service (assuming it's running).

sudo /etc/init.d/sendmail stop

Uninstall sendmail and sendmail-bin