Skip to content

Instantly share code, notes, and snippets.

View bpceee's full-sized avatar
💭
In meditation

Ken Bi bpceee

💭
In meditation
  • Auckland, New Zealand
View GitHub Profile
@bpceee
bpceee / cypressFileUpload.js
Created March 17, 2020 03:23
cypress file upload
const uploadFile = (fileName, fileType = '', selector) => {
cy.get(selector).then(subject => {
cy.fixture(fileName, 'base64')
.then(Cypress.Blob.base64StringToBlob)
.then(blob => {
const el = subject[0]
const testFile = new File([blob], fileName, { type: fileType })
const dataTransfer = new DataTransfer()
dataTransfer.items.add(testFile)
el.files = dataTransfer.files
let styleEl;
let keyframeID = 0;
const insertionObserver = function(selector, callback) {
if (!styleEl) {
styleEl = document.createElement('style');
document.head.appendChild(styleEl);
}
const curKeyframeName = `insertionObserver${keyframeID++}`;
const keyframesRule = `@keyframes ${curKeyframeName} { from { opacity: 0.99; } to { opacity: 1; } }`;
const styleRule = `${selector} { animation-duration: 0.001s; animation-name: ${curKeyframeName}; }`;
@bpceee
bpceee / stash-avatar-initials.js
Last active November 21, 2018 09:29
stash avatar initials
// ==UserScript==
// @name stash avatar initials
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://stash.bbpd.io/*
// @grant none
// ==/UserScript==
@bpceee
bpceee / openOdestCommitPage.js
Created May 23, 2018 10:52
openOdestCommitPage
(function openOdestCommitPage([_, repo, branch='master']) {
return fetch('https://api.github.com/repos/' + repo + '/commits?sha=' + branch)
// the link header has additional urls for paging
// parse the original JSON for the case where no other pages exist
.then(res => Promise.all([res.headers.get('link'), res.json()]))
// get last page of commits
.then(([link, commits]) => {
if (!link) {
return;
}
set -g default-terminal "screen-256color"
# remap prefix to Control + a
set -g prefix C-a
# bind 'C-a C-a' to type 'C-a'
bind C-a send-prefix
unbind C-b
#Force a reload of the config file
@bpceee
bpceee / jsType.js
Created August 22, 2017 03:43
get real js type
function type(obj) {
var toString = Object.prototype.toString;
var map = {
'[object Boolean]' : 'boolean',
'[object Number]' : 'number',
'[object String]' : 'string',
'[object Function]' : 'function',
'[object Array]' : 'array',
'[object Date]' : 'date',
'[object RegExp]' : 'regExp',
@bpceee
bpceee / scopeWalker.js
Last active March 31, 2017 06:37
walk angular 1.x scope tree
function scopeWalker(scope, op) {
var _walker = (scope) => {
op(scope);
var currentChildScope = scope.$$childHead;
while(currentChildScope) {
_walker(currentChildScope);
currentChildScope = currentChildScope.$$nextSibling;
}
}
_walker(scope);
@bpceee
bpceee / gist:5eebb82b40fb4abd450fab106352687d
Last active March 17, 2017 07:35
angular 1.x measure digest time
angular.element(document)
.injector()
.invoke(['$rootScope', function($rootScope) {
var a = performance.now();
$rootScope.$apply();
return performance.now()-a;
}])
angular.element(document)
@bpceee
bpceee / index.html
Last active October 20, 2016 06:10
set caret(cursor) position in contenteditable element (div)
<html>
<!-- http://jsfiddle.net/timdown/vXnCM/-->
<head>
<title>Get/Set Caret in Textarea Example</title>
<script>
function test() {
var el = document.getElementById('editable');
var range = document.createRange();
@bpceee
bpceee / gist:9bc0c8536eae94143f4486e4e47a5fc3
Last active October 19, 2016 09:12
Get/set Cursor In Html TextArea
<html>
<!-- http://snipplr.com/view/5144/getset-cursor-in-html-textarea/ -->
<head>
<title>Get/Set Caret in Textarea Example</title>
<script>
function doGetCaretPosition (ctrl) {
var CaretPos = 0;
// IE Support
if (document.selection) {