Skip to content

Instantly share code, notes, and snippets.

View samtsai's full-sized avatar
🏠
Working from home

Sam Tsai samtsai

🏠
Working from home
View GitHub Profile
@samtsai
samtsai / setup_launch_agents.sh
Created March 26, 2014 17:39
Setup launch agents (useful for automating brew installs and their startup script)
# Set Up Launch Agent to Run On Startup
function set_launch_agent() {
# retrieve the dependency's prefix
DEP_PREFIX=$(brew --prefix ${1})
# make the user local LaunchAgents directory (skip if already exists)
mkdir -p ~/Library/LaunchAgents
# copy brew generated plist to LaunchAgent
cp $DEP_PREFIX/*${1}*.plist ~/Library/LaunchAgents/
# load the agent now
launchctl load -w ~/Library/LaunchAgents/*${1}*.plist
@samtsai
samtsai / cy-all.ts
Created April 18, 2022 18:22
Typed `cy.all([...])` command for Cypress consumers
// @see https://github.com/cypress-io/cypress/issues/915#issuecomment-475862672
// Modified due to changes to `cy.queue` https://github.com/cypress-io/cypress/pull/17448
// Note: this DOES NOT run Promises in parallel like `Promise.all` due to the nature
// of Cypress promise-like objects and command queue. This only makes it convenient to use the same
// API but runs the commands sequentially.
declare namespace Cypress {
type ChainableValue<T> = T extends Cypress.Chainable<infer V> ? V : T
interface cy {
@samtsai
samtsai / selection-command.js
Last active March 6, 2021 19:37 — forked from erquhart/selection-command.js
Text selection commands for Cypress.io
/**
* Credits
* @Bkucera: https://github.com/cypress-io/cypress/issues/2839#issuecomment-447012818
* @Phrogz: https://stackoverflow.com/a/10730777/1556245
*
* Usage
* ```
* // Types "foo" and then selects "fo"
* cy.get('input')
* .type('foo')
@samtsai
samtsai / billion.xml
Created January 27, 2021 22:10
Test Billion laughs
<?xml version="1.0"?>
<!DOCTYPE lolz [
<!ENTITY lol "lol">
<!ELEMENT lolz (#PCDATA)>
<!ENTITY lol1 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">
<!ENTITY lol2 "&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;">
<!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;">
<!ENTITY lol4 "&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;">
<!ENTITY lol5 "&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;">
<!ENTITY lol6 "&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;">
import Ember from 'ember';
export default Ember.Component.extend({
logger: Ember.inject.service()
});
@samtsai
samtsai / asap.js
Last active February 21, 2017 19:32
As soon as possible - simple asynchronous script loading library
// ASAP Library
// use case
/*
add omniture to registry
omniture tags are waiting to fire
asap loads omniture asynchronously
page waits for omniture to be ready
omniture loads
asap announces omniture is ready
@samtsai
samtsai / components.my-component.js
Created June 14, 2016 21:29 — forked from jpadilla/components.my-component.js
Component Lifecycle Hooks
import Ember from 'ember';
export default Ember.Component.extend({
init(options) {
console.log('init', options);
},
didUpdateAttrs(options) {
console.log('didUpdateAttrs', options);
},
@samtsai
samtsai / npm short list
Created December 4, 2013 15:13
List npm global modules installed without dependencies
npm ls --depth 0 -g
@samtsai
samtsai / normalize analytic strings
Created May 7, 2013 15:32
quick normalize functions for grooming strings passed into an analytics library like SiteCatalyst
// this would be set in a closure
// but leave some values to be cached (ie not created every function call)
// and the ability to override
var norm_regex = /\s+/g;
var norm_replace = "_";
function normalize( val, reg_pattern, separator ) {
// convert to string
var norm_val = val+"";
norm_regex = reg_pattern || norm_regex;
@samtsai
samtsai / Perf.md
Created August 16, 2012 14:30
Gist.io - a new way to write?

Perf Notes

Souders

The true cause of frontend SPOF is loading a script, stylesheet, or font file in a blocking manner.

Tag management/TAAS/Universal Tagging/etc.