Skip to content

Instantly share code, notes, and snippets.

View sansmischevia's full-sized avatar

Bryant Chou sansmischevia

  • Webflow
  • San Francisco, CA
View GitHub Profile

Below is a JavaScript code snippet that tracks Time to First Paint(TFP), Time to First Contentful Paint(TFCP), Latency, and some other critical performance metrics. It then sends this data in a JSON format to an endpoint.

(function() {
  document.addEventListener('DOMContentLoaded', function(){
    var performance = window.performance || window.mozPerformance || window.msPerformance || window.webkitPerformance || {};
    var performanceTiming = performance.timing;
    var analyticsData = {}; // To store the metrics

    // Time to First Paint (TFP)
@sansmischevia
sansmischevia / nginx.conf
Last active July 3, 2023 15:26
nginx http proxy to s3 static websites
##
## This nginx.conf servers as the main config file for webflow reverse proxy
##
## RCS:
## https://gist.github.com/sansmischevia/5617402
##
## Hardening tips:
## http://www.cyberciti.biz/tips/linux-unix-bsd-nginx-webserver-security.html
##
@sansmischevia
sansmischevia / value.js
Created March 12, 2013 23:41
convert DynamoDb JSON to regular JSON javascript objects
function Value(value) {
switch (typeof value) {
case "number": return {N: String(value)}
case "string": return {S: value}
}
if (value) switch (typeof value[0]) {
case "number": return {NS: value.map(String)}
case "string": return {SS: value}
}
@sansmischevia
sansmischevia / mixpanel-last-touch-UTM.js
Last active March 21, 2018 22:12
Mixpanel Last Touch UTM tracking
function getQueryParam(url, param) {
// Expects a raw URL
param = param.replace(/[[]/, "\[").replace(/[]]/, "\]");
var regexS = "[\?&]" + param + "=([^&#]*)",
regex = new RegExp(regexS),
results = regex.exec(url);
if (results === null || (results && typeof(results[1]) !== 'string' && results[1].length)) {
return '';
} else {
return decodeURIComponent(results[1]).replace(/\W/gi, ' ');
function getQueryParam(url, param) {
// Expects a raw URL
param = param.replace(/[[]/, "\[").replace(/[]]/, "\]");
var regexS = "[\?&]" + param + "=([^&#]*)",
regex = new RegExp(regexS),
results = regex.exec(url);
if (results === null || (results && typeof(results[1]) !== 'string' && results[1].length)) {
return '';
} else {
return decodeURIComponent(results[1]).replace(/\W/gi, ' ');
<style>
::selection {
background: #000; /* WebKit/Blink Browsers */
color: white;
}
@sansmischevia
sansmischevia / bryant.key
Last active November 30, 2017 14:55
Webflow Infrastructure Project
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC8zm/C7tp8ke37hapZbzhCzCOd9UfajpEjih42QxcgX60NQc2P99FyOLwFavXBps/jq+kXC7tEnXSD1qUvxAWg4X5/zKGRokbYvG5b9f4SwBIWEYOOdXn+iZYSadeQRGPMrDvDPSeaZVN372F8BLx0YYxb0sJ9pO3XTbz4E+ngyw+dp99PP/AVwMJZeStkPwp8wM6FQ9JkPsBHRMkgsu2HPi62VVs9R+itzj11MVaQmax/Kvlp/JxFe0S2ANixBNYcTE9yO0AxCIMMFplMjO/XK0Ae552SHnzroO3KRqw3eD9Aapm+/YrEMIA9cUmwwDS2byWQfFJd356y4AwM4b5F chou.bryant@gmail.com
@sansmischevia
sansmischevia / Graphite on Amazon Linux
Last active August 10, 2017 12:01 — forked from outmost/Graphite on Amazon Linux
Sets up graphite, carbon, whisper, and statsd on ami-3275ee5b
# AMI: ami-3275ee5b
# Login: ec2-user
# Apply updates
sudo yum update
# Enable Epel Repo
sudo vim /etc/yum.repos.d/epel.repo.
# Under the section marked [epel], change enabled=0 to enabled=1.
@sansmischevia
sansmischevia / gist:e04fe20bf6623cc04361
Created January 20, 2015 00:28
sudo gem install knife-ec2
Building native extensions. This could take a while...
ERROR: Error installing knife-ec2:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20150119-12518-1qmgu0.rb extconf.rb
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.
checking for iconv... yes
************************************************************************
@sansmischevia
sansmischevia / org-mongodb-mongod-plist
Created April 3, 2013 08:14
launchctl plist for mongodb. path: /Library/LaunchDaemons/org.mongodb.mongod.plist
<key>HardResourceLimits</key>
<dict>
<key>NumberOfFiles</key>
<integer>1024</integer>
</dict>
<key>SoftResourceLimits</key>
<dict>
<key>NumberOfFiles</key>
<integer>1024</integer>
</dict>