Skip to content

Instantly share code, notes, and snippets.

View philippkuehn's full-sized avatar
🤦‍♂️
Coding

Philipp Kühn philippkuehn

🤦‍♂️
Coding
View GitHub Profile
@ljharb
ljharb / array_iteration_thoughts.md
Last active October 24, 2024 07:30
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

@giannis
giannis / gist:5256701
Last active December 15, 2015 11:59
This script starts mamp app without the need for a sudo password. In order to work you need to add a login entry on your keychain
#initial code from http://www.tech-otaku.com/local-server/starting-mamps-apache-mysql-servers-login/
tell application "Finder"
# Check if the Apache or MySQL servers are already running
set apacheRunning to my ProcessRunning("httpd")
set mysqlRunning to my ProcessRunning("mysqld")
# If neither the Apache nor MySQL servers are already running...
if (not apacheRunning and not mysqlRunning) then
# get the user name and password using the security Terminal command
set theUserName to do shell script ("security find-generic-password -l \"MAMP\" | grep \"acct\" | cut -c 19-99 | tr -d '\"'")