Skip to content

Instantly share code, notes, and snippets.

@ironboy
ironboy / gist:f5b6663ea4c9704efb5aeda248386343
Last active February 5, 2024 12:26
Idea find iframe play button trailer
const getIframeDocument = () => {
return cy
.get('iframe[title="YouTube video player"]]')
// Cypress yields jQuery element, which has the real
// DOM element under property "0".
// From the real DOM iframe element we can get
// the "document" element, it is stored in "contentDocument" property
// Cypress "its" command can access deep properties using dot notation
// https://on.cypress.io/its
.its('0.contentDocument').should('exist')
@ironboy
ironboy / check.js
Created February 5, 2024 10:14
Idea checking play trailer
const getIframeDocument = () => {
return cy
.get('iframe[title="Trailer"]]')
// Cypress yields jQuery element, which has the real
// DOM element under property "0".
// From the real DOM iframe element we can get
// the "document" element, it is stored in "contentDocument" property
// Cypress "its" command can access deep properties using dot notation
// https://on.cypress.io/its
.its('0.contentDocument').should('exist')
@ironboy
ironboy / all-straights.js
Created April 19, 2023 12:12
Straights.... (pokerhand test - example loop)
const ranks = '23456789TJQKA';
const suits = '♥♦♣♠';
// Fake class for hand
// replace with importing real class
class Hand {
constructor() {
console.log([...arguments])
}
}
@ironboy
ironboy / states.js
Created December 28, 2022 15:57
Simplify context, states and form handling in React
// Simplify states, contexts and binding to forms
// ironboy 2022
import { useState, useDebugValue } from 'react';
const savedStates = {};
export function useStates(initObj, contextName) {
typeof initObj === 'string'
@ironboy
ironboy / auto-key-lists.js
Last active December 28, 2022 15:40
Auto create keys in React lists
// Omits the need to write 'key={someUniqueKey}'
// for elements in list when mapping them to jsx
// - automatically tries to get the key from id or _id,
// if not possible, uses the array index instead
let ap = Array.prototype;
if (!ap._mapNoAutoKey) {
let org = ap._mapNoAutoKey = ap.map;
ap.map = function (...args) {
// get ids/unique keys
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
window.onXhr = require('on-xmlhttprequest');
},{"on-xmlhttprequest":2}],2:[function(require,module,exports){
var EventEmitter = require('events').EventEmitter;
var oldOpen = window.XMLHttpRequest.prototype.open;
module.exports = function (onrequest) {
function open () {
var emitter = new EventEmitter();
var xhr = this;
from threading import Thread
from datetime import datetime
from network import connect, send
# convert timestamp to iso date time format
def timestamp_to_iso(timestamp):
return datetime.fromtimestamp(timestamp / 1000)\
.isoformat().replace('T', ' ').split('.')[0]
def send_message():
@ironboy
ironboy / storageWrapper.js
Created December 19, 2016 13:51
Small localStorage wrapper
function lStore(key,val){
var parsed = JSON.parse(localStorage.store || '{}');
if(val === undefined){
// read
return parsed[key];
}
// write
parsed[key] = val;
localStorage.store = JSON.stringify(parsed);
}
@ironboy
ironboy / pingpong_sort_up.js
Last active October 6, 2016 08:31
Sort filelists in PingPong
if(!window.jQuery){
var scr = document.createElement('script');
scr.src = 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js';
document.getElementsByTagName('head')[0].appendChild(scr);
}
var jwait = setInterval(function(){
if(!window.jQuery){return;}
clearInterval(jwait);
var $ = jQuery;
var table = $('#ppfdata').contents().find('.file-archive-table');
@ironboy
ironboy / minisuper.js
Created February 29, 2016 18:53
Object.create patterns - with simple super
// The supershort version
// with no extras (as super, named constructors etc.)
// And nice way to handle inheritance is by creating a base object
// with an extend method
var Base = {
extend: function(props){
// A new object with this object as its prototype
var t = this, obj = Object.create(t);
// Assign properties to the new object