Skip to content

Instantly share code, notes, and snippets.

View mantismamita's full-sized avatar

Kirsten Cassidy mantismamita

View GitHub Profile
console.clear()
function assertEquals<T>(
found: T,
expected: T,
message: string
) {
if (found !== expected)
throw new Error(
`❌ Assertion failed: ${message}\nexpected: ${expected}\nfound: ${found}`
const getStyle = (classOrId, property) => {
var firstChar = classOrId.charAt(0);
var remaining= classOrId.substring(1);
var elem = (firstChar =='#') ? document.getElementById(remaining) : document.getElementsByClassName(remaining)[0];
if(elem) {
return window.getComputedStyle(elem).getPropertyValue(property);
}
return;
}
@mantismamita
mantismamita / customEvent.js
Last active January 9, 2020 10:28
Creates a custom event
function setCustomEvent (dispatcher, eventName, dataObj) {
let event
if (window.CustomEvent) {
event = new CustomEvent(eventName, { detail: dataObj })
} else {
event = document.createEvent('CustomEvent')
event.initCustomEvent(eventName, true, true, dataObj)
}
return dispatcher.dispatchEvent(event)
@mantismamita
mantismamita / docker.md
Last active December 28, 2019 09:42
docker cheatsheet

Docker CLI

docker kill $(docker ps -q) kills all running processes without having to list ids individually

docker run --init --rm -p 3000:3000 my-node-app

Dockerfile

@mantismamita
mantismamita / console.js
Created December 20, 2019 22:20 — forked from Harshmakadia/console.js
Mastering JS console like a Pro
// time and time end
console.time("This");
let total = 0;
for (let j = 0; j < 10000; j++) {
total += j
}
console.log("Result", total);
console.timeEnd("This");
// Memory
.hidden-all {
display: none;
}
.hidden-visually {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
overflow: hidden;
@mantismamita
mantismamita / utility.ts
Last active May 11, 2022 15:59
js algorithm utility functions
// greatest common denominator
const gcd = (a, b) => b ? gcd(b, a % b) : a
// lowest common multiplier
const lcm = (a, b) => (a * b)/ gcd(a, b)
// some Date stuff for safe-keeping
const weekdayMonthFormat = {
weekday: 'long',
day: 'numeric',
function stickSharebar () {
if ($W.scrollTop() < parseInt($offset)) {
$el.addClass('in-article')
$menuBtn.css('bottom', '20px')
} else {
$el.removeClass('in-article')
$menuBtn.css('bottom', '60px')
}
if (($W.scrollTop() > parseInt($offset + 1)) && (window.matchMedia('(min-width: 620px)').matches)) {
@mantismamita
mantismamita / findChildWithClass
Created January 30, 2018 10:39
ES6 only (due to Array.from())
let findChildWithClass = (parent, classname) => {
let children = Array.from(parent.children)
for (let child of children) {
if (child.classList.contains(classname)) {
return child
}
}
}
@mantismamita
mantismamita / admin_from_ftp.php
Created September 18, 2015 10:24
create admin account from ftp access
function admin_account(){
$user = 'developer';
$pass = 'mypassword';
$email = 'emailme@hmamail.com';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
} }
add_action('init','admin_account');