Skip to content

Instantly share code, notes, and snippets.

Cheat sheet: JavaScript Array methods

Deriving a new Array from an existing Array:

['■','●','▲'].slice(1, 3)           ['●','▲']
['■','●','■'].filter(x => x==='■')  ['■','■']
    ['▲','●'].map(x => x+x)         ['▲▲','●●']
    ['▲','●'].flatMap(x => [x,x])   ['▲','▲','●','●']
@arei
arei / 10ThingsWrongWebComponents.md
Last active February 20, 2024 03:16
10 Things You Are Doing Wrong in your Web Components

10 Things You Are Doing Wrong in your Web Components

Web Components enable custom element creation and sharing on a whole new level that has not really been seen to date but is so desperately needed. Developers of everything from simple webpages to complex applications are using Web Components to deliver new functionality, new behaviors, and new designs. Web Components are a big part of the future of the web.

There are lots of articles detailing how to build a basic Web Component, but almost no article details how to solve some of the gotchas once you start down that road. That's what this article serves to do; point out some of the things every Web Component developer is overlooking and to which they should probably be giving more consideration.

1). Not Using a Web Component Framework

The APIs which make up the Web Components standards (Custom Elements, ShadowDOM, etc) are intentionally low level APIs. As such they are not always the most clear or concise in their understandability. Additionally,

<?php
/**
* Plugin Name: YOUR PLUGIN NAME
*/
include( dirname( __FILE__ ) . '/lib/requirements-check.php' );
$your_plugin_requirements_check = new YOUR_PREFIX_Requirements_Check( array(
'title' => 'YOUR PLUGIN NAME',
'php' => '5.4',
@shospodarets
shospodarets / Chrome headless Puppeteer- capture DOM element screenshot using
Last active January 17, 2023 18:52
Chrome headless Puppeteer- capture DOM element screenshot using
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// Adjustments particular to this page to ensure we hit desktop breakpoint.
page.setViewport({width: 1000, height: 600, deviceScaleFactor: 1});
await page.goto('https://www.chromestatus.com/samples', {waitUntil: 'networkidle'});
@abritinthebay
abritinthebay / consoleColors.js
Last active April 26, 2024 00:33
The various escape codes you can use to color output to StdOut from Node JS
// Colors reference
// You can use the following as so:
// console.log(colorCode, data);
// console.log(`${colorCode}some colorful text string${resetCode} rest of string in normal color`);
//
// ... and so on.
export const reset = "\x1b[0m"
export const bright = "\x1b[1m"
export const dim = "\x1b[2m"
@harrisj
harrisj / times_machine.rb
Created April 10, 2016 01:34
My hackish Ruby script for hopping to a random NYT issue in the years 1851 - 1922 (ie, in the public domain)
#!/usr/bin/env ruby
years = (1851..1922).to_a
months = (1..12).to_a
def max_day_for_month(month, year)
case month
when 1, 3, 5, 7, 8, 10, 12
31
when 9, 4, 6, 11
@wheresalice
wheresalice / deleter.rb
Created July 16, 2013 19:20
Most twitter APIs can only handle the most recent 3200 tweets from a user, this tool uses your twitter download to delete anything older than this. After doing this you can now use the more traditional API tools to delete your old tweets It would be nice to have the option of only deleting tweets without replies or retweets, but that would get r…
require 'twitter' # gem install twitter <https://github.com/sferik/twitter>
require 'csv' # requires Ruby > 1.9
# Edit these to your own settings
Twitter.configure do |config|
config.consumer_key = ''
config.consumer_secret = ''
config.oauth_token = ''
config.oauth_token_secret = ''
end
@robinsloan
robinsloan / langoliers.rb
Last active April 7, 2024 13:22
The Langoliers, a tweet deletion script
require "rubygems"
require "twitter"
require "json"
# things you must configure
TWITTER_USER = "your_username"
MAX_AGE_IN_DAYS = 1 # anything older than this is deleted
# get these from dev.twitter.com
CONSUMER_KEY = "your_consumer_key"
@nathansmith
nathansmith / last_child.js
Created May 1, 2011 19:26
Force IE7 & IE8 to respect :last-child
// Heavy-handed way to force IE7 & IE8 to respect :last-child.
// Note: Using jQuery. Adjust to suit your library, etc.
//
// Style via...
//
// element:last-child,
// element.last-child {
// /* Style here */
// }
//