Skip to content

Instantly share code, notes, and snippets.

View JimOfLeisure's full-sized avatar
Having a leisurely day

Jim Nelson JimOfLeisure

Having a leisurely day
View GitHub Profile
@JimOfLeisure
JimOfLeisure / Array.prototype.unique.js
Created May 4, 2022 22:39
Idea swiped from someone wanting to avoid using Set for getting unique values
Array.prototype.unique = function () { return this.filter((e, i, a) => i === a.indexOf(e)) };
function sentencify(words) {
const str = words.join(' ');
return str[0].toUpperCase() + str.slice(1) + '.';
}
@JimOfLeisure
JimOfLeisure / one-liner.js
Created March 3, 2022 07:22
Figured out the spread syntax after the time expired
function orderFood(list) {
return list.reduce((a, {meal}) => ({...a, [meal]: a[meal] + 1 || 1}), {});
}
function countLanguages(list) {
return list.reduce((p, c) => {
if (p[c.language]) p[c.language] += 1
else p[c.language] = 1;
return p;
}, {})
}
@JimOfLeisure
JimOfLeisure / codewar-thingy.js
Created January 27, 2022 05:53
An example during a stream
function spoonerize(words) {
output = new Array();
let wordList = words.split(' ');
for (let i=0; i<wordList.length; i++) {
let myWord = wordList[i].replace(/^./, wordList[wordList.length - i - 1][0]);
output.push(myWord)
}
return output.join(' ');
}
@JimOfLeisure
JimOfLeisure / callback.lua
Last active January 13, 2022 07:16
Just a quick demo of a callback in Lua, inspired by a Discord discussion
local function just_print_it(text)
print(text)
end
local function print_it_backwards(text)
print(string.reverse(text))
end
local function do_something(text, callback)
-- do neat stuff
@JimOfLeisure
JimOfLeisure / zoom-to-markdown.sh
Created January 8, 2022 18:38
Zoom chat to markdown quotes one-liner
sed -e 's/.*/> &/'| sed -e 's/.* to Everyone .*/\n&/' | pbcopy
# A cut-and-paste command. I'm using this then pasting the contents of a Zoom call chat
# The results are markdown-quoted messages with line breaks between each participant
# pbcopy is the Mac utility to capture to the clipboard. Linux & Windows may have different commands
@JimOfLeisure
JimOfLeisure / set-aws-creds.sh
Last active January 7, 2022 18:09
A copy & paste thing to enter AWS keys without having them show up in command history or on-screen
echo "Paste in AWS_ACCESS_KEY_ID" && \
read -s AWS_ACCESS_KEY_ID && \
echo "Paste in AWS_SECRET_ACCESS_KEY" && \
read -s AWS_SECRET_ACCESS_KEY && \
export AWS_ACCESS_KEY_ID && \
export AWS_SECRET_ACCESS_KEY && \
echo "aws key ready for use"
a=math b=240 c=138 d=120 e=69 f=0 g=0 h=0 i=.5 j=.2 k=.5
function l()m=d n=e o=0 p=0 q=0 r=0 end
l()
function TIC()t=a.sin(a.rad(f))u=-a.cos(a.rad(f))m=m+o n=n+p q=q+i r=r+j
if btnp(4)then m=d+t*9 n=e+u*9 o=t*2 p=u*2 end
if btn(2)then f=f-4 end
if btn(3)then f=f+4 end
cls()circ(d,e,7,8)print("*",(q-6)%b,(r-4)%c,6,true,2)circ(q%b,r%c,2,6)
if pix(m%b,n%c)==6 then g=g+1 k=k*1.2 i=k*t j=k*u l()end
print("SCORE "..g.." HI "..h,9,0)pix(m%b,n%c,15)line(d,e,d+t*9,e+u*9,15)