Skip to content

Instantly share code, notes, and snippets.

View DarrenSem's full-sized avatar

Darren Semotiuk DarrenSem

View GitHub Profile
@ljharb
ljharb / array_iteration_thoughts.md
Last active February 14, 2026 23:20
Array iteration methods summarized

Array Iteration

https://gist.github.com/ljharb/58faf1cfcb4e6808f74aae4ef7944cff

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it mu

@LeCoupa
LeCoupa / bash-cheatsheet.sh
Last active February 11, 2026 10:15
Bash CheatSheet for UNIX Systems --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
#!/bin/bash
#####################################################
# Name: Bash CheatSheet for Mac OSX
#
# A little overlook of the Bash basics
#
# Usage:
#
# Author: J. Le Coupanec
# Date: 2014/11/04
@lalkmim
lalkmim / codility_solutions.txt
Last active January 5, 2026 04:00
Codility Solutions in JavaScript
Lesson 1 - Iterations
- BinaryGap - https://codility.com/demo/results/trainingU2FQPQ-7Y4/
Lesson 2 - Arrays
- OddOccurrencesInArray - https://codility.com/demo/results/trainingFN5RVT-XQ4/
- CyclicRotation - https://codility.com/demo/results/trainingSH2W5R-RP5/
Lesson 3 - Time Complexity
- FrogJmp - https://codility.com/demo/results/training6KKWUD-BXJ/
- PermMissingElem - https://codility.com/demo/results/training58W4YJ-VHA/
# SYNTAX:
var pattern = new RegExp(pattern, attributes); # attributes: g (global); i (case-sensitive); m (multiline matches)
var pattern = /pattern/attributes; # same as above
# BRACKETS:
[...]: Any one character between the brackets.
[^...]: Any one character not between the brackets.
# NPM CheatSheet.
# Super easy intall: npm comes with node now.
# To create your own npm package: https://www.npmjs.org/doc/misc/npm-developers.html
# More: https://www.npmjs.org/doc/
# 1. NPM Command Lines.
# Local mode is the default.
# Use --global or -g on any command to operate in global mode instead.
@gaearon
gaearon / index.html
Last active October 21, 2025 03:08
Multiple React components on a single HTML page
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Add React in One Minute</title>
</head>
<body>
<h2>Add React in One Minute</h2>
<p>This page demonstrates using React with no build tooling.</p>
@DarrenSem
DarrenSem / MarkDownLivePreview.com-resizer.js
Last active September 13, 2025 01:34
MarkDownLivePreview.com-resizer.js -- bookmarklet to add [Toggle Editor] (and also horizontal resizer)
//// Update: Go here instead, works as a Bookmarklet or as an included file via <script src="...">. (I also added a printButton.js)
//// https://github.com/DarrenSem/markdown/blob/master/static/resizer.js
// MarkDownLivePreview.com-resizer.js -- bookmarklet to add 'Toggle Editor' (and also width-resizer) - instead of waiting for repo update that might use something like this <script src="./static/resizer.js"></script>
// (09Sep2025 938am) 2209 char javascript:void function(){"use strict";const e="minedit",t="extra-button",i="mouse",n="width",r=document,o=e=>r.getElementById(e),s=(e,t)=>Object.assign(r.createElement(e||"div"),t),d=(e,...t)=>e.addEventListener(...t),l=(e,...t)=>e.removeEventListener(...t),a=e=>e.preventDefault(),c=setTimeout,g=40,m=window,f=(e="resizer-css")=>{if(o(e))return;const i=["\nbody {\n margin: 0;\n height: 100vh;\n overflow: hidden;\n}\n#container {\n display: flex;\n width: 100%;\n height: 100%;\n overflow: hidden;\n}\n#resizer {\n width: 4px;\n background-color: green;\n
@zedeus
zedeus / following.py
Created September 2, 2019 21:06
Fetch Twitter following list
import requests, re, sys
url = "https://mobile.twitter.com/{}/following"
cursor = ""
usernames = []
first = True
if len(sys.argv) < 2:
print("Usage: python followers.py <username>")
quit(1)
@DarrenSem
DarrenSem / width.js
Last active April 14, 2025 15:51
width.js - Bookmarklet for OpenAI playground to fix maxWidth of "Configure" panel (due to latest layout update); add as browser Favorite then click to toggle visibility
// width.js - Bookmarklet for OpenAI playground to fix maxWidth of "Configure" panel (due to latest layout update); add as browser Favorite then click to toggle visibility
// https://gist.github.com/DarrenSem/0d9da09fc5a7b95abcc0df95d65b02c7
// 05Apr2025 234pm: will now FIRST close "Configure" if already opened as slide-in panel version (could have BOTH versions visible!)
// 2016 char javascript:void function(){const a=null,b="innerText",c=(b,c=1)=>{let d=b;for(;c--&&(d=d?.parentElement););return d||a},d=(a,b)=>a.test(b??""),e=()=>{const a=document.querySelectorAll("button > span > span + span.sr-only"),c=Array.from(a).filter((a,c)=>{const e=a[b],f=d(/Configure/,e);return console.log({isTextConfigure:f,text:e,el:a,i:c}),f});return console.log({collConfigureButtons:c,collButtonSpans:a,selButtonSpans:"button > span > span + span.sr-only"}),c},f=e=>{let f,g,h=a;const i=c(e,1),j=i.querySelectorAll("button");for(f of j)if(g=f.dataset,console.log({dataset:g,elButton:f}),!d(/\S/,f[b])&&"secondary"==g?.color&&"md"
@DarrenSem
DarrenSem / above(parentElement).js + next(siblingElement).js
Created April 14, 2025 15:48
above.js (PARENT element, levels = #) + next.js (SIBLING element, levels = #) helper functions instead of foo.parentElement.parentElement.parentElement etc.
// above.js (PARENT element, levels = #) + next.js (SIBLING element, levels = #) helper functions instead of foo.parentElement.parentElement.parentElement etc.
// https://gist.github.com/DarrenSem/4d37711fb71a484b6ed2356c60e3c94a
// PARENT element: ...
const above = (startingElement, levels = 1) => {
let el = startingElement;
while ( levels-- && (el = el?.parentElement) );
return el || null;