Skip to content

Instantly share code, notes, and snippets.

View lewdev's full-sized avatar

Lewis Nakao lewdev

View GitHub Profile
@lewdev
lewdev / #downloadToFile.md
Created April 12, 2023 00:52
Download text to a file (πŸ”–Bookmarklet)

Download text to a file

Code that will take a filename and text data and have the user download it.

Run it in your address bar (Bookmarklet)

data:text/html,<input id="filenameInput" value="file-to-save.txt"/><button onclick="downloadToFile(filenameInput.value, contentInput.value)">Download File</button><textarea id="contentInput" style="width:100%" rows="10">Content</textarea><script>const downloadToFile=(filename,content)=>{if(!content){alert("No content to save!");return;}
const a=document.createElement("a");const file=new Blob([content],{type:"text/plain"});a.href=URL.createObjectURL(file);a.download=filename;a.click();URL.revokeObjectURL(a.href);};</script>
@lewdev
lewdev / #readme.md
Last active December 13, 2023 22:09
😼 Markdown Editor in your address bar (πŸ”– bookmarklet)

😼 Markdown Editor in your address bar (πŸ”– bookmarklet)

A live markdown editor in a bookmarklet. Preview is updated on every key press. I should implement a delay.

It's a lot of code, but I like the nature of bookmarklets where nothing is retained after you close it.

I often find myself just wanting to see what the markdown looks like, which is why I built this.

I used Snarkdown, a 1kb markdown parser. I did try to make my own parser but I gave up.

@lewdev
lewdev / #code-input-expected-output.md
Last active April 11, 2023 00:52
⌨ Code, Input, Expected, & Output for Testing (πŸ”–Bookmarklet)

⌨ Code, Input, Expected, & Output for Testing

A JavaScript code testing that emulates code.golf, LeetCode, HackerRank, etc.

Press Ctrl + Enter to run the test.

I find myself running this kind of test pattern and wanting to avoid using their UIs. There are limiations there including speed and rate of testing. Using their system is too slow.

For now this only runs one test case and compares the output with the expected values.

@lewdev
lewdev / #json-to-sql-insert.md
Last active April 6, 2023 02:26
πŸ”’ How to convert JSON to an SQL Insert Statement

πŸ”’ How to convert JSON to an SQL Insert Statement

I found some issues with this article, so I decided to write my own article about it.

This page will explain the solution to convert this:

{
  "firstName": "James",
  "lastName": "Smith",
 "strength": 70,
@lewdev
lewdev / ninja-phone-by-chatgpt.md
Last active March 22, 2023 01:46
πŸ±β€πŸ‘€ Ninja Phone By ChatGPT

πŸ±β€πŸ‘€ Ninja Phone By ChatGPT

In a casual conversation, someone mentioned making a "Ninja Phone" game and I wondered what ChatGPT would give me out of that.

It didn't give anything I expected but it was a somewhat working game.

The limitations are that ChatGPT has a limit to how much it will output, so adding code-golfed version helps with getting more out of it.

The code-golfing ability was okay. When I said "minified," It didn't understand what I meant, so I changed it to code-golfed version and it worked.

@lewdev
lewdev / worksheet-generators.md
Last active September 25, 2024 04:46
πŸ«πŸ“„ Worksheet Generators List

πŸ«πŸ“„ Worksheet Generators

For inspiration and ideas for my Math Homework Generator, I figured that I should start a list of pages I should look through eventually to learn about what's out there and what might be lacking. MHG is often found in other lists which is how I found these links.

Custom Resource Makers - Worksheet Generators (Source)

@lewdev
lewdev / pet-sim.html
Last active June 7, 2025 01:40
🐢 Simple Pet Sim
<!DOCTYPE html>
<head><title>🐢 Pet Sim</title></head>
<body>
<div id="start">
<h2>🐢 What would you like to name your pet?</h2>
<input id="n" onkeyup="event.keyCode===13&&n.value?start_game(n.value):null"/>
<button onclick="start_game(n.value)">Start</button>
</div>
<div id="controls" style="display:none">
@lewdev
lewdev / nth-fibonacci.html
Last active September 16, 2025 20:57
πŸ”’ Nth Fibbonacci bookmarklet (99b)
data:text/html,<input id=o onblur=with(Math)r=sqrt(5),o.value=round(pow((1+r)/2,o.value)/r)>
@lewdev
lewdev / date-distance.html
Last active February 27, 2023 04:03
πŸ“… Date Distance JavaScript function (i.e. "3mo ago", "5d until")
<pre id=o></pre>
<script>
const TIME = [1e3, "s", 6e4, "min", 36e5, "hr", 864e5, "d", 2592e6, "wk", 2592e6, "mo", 31536e6, "yr"];
const dateDistance = dateStr => {
const now = new Date().getTime();
let diff = now - new Date(dateStr).getTime();
let agoOrUntil = " ago";
if (diff < 0) { agoOrUntil = " until"; diff = Math.abs(diff); }
for (let i = 12; i >= 0; i-=2) {
@lewdev
lewdev / smb-in-url.md
Last active September 27, 2024 01:16
πŸ¦˜πŸ‘¨β€πŸ”§ Super Mario Bros in your URL

πŸ¦˜πŸ‘¨β€πŸ”§ Super Mario Bros in your URL

This was made by xem or @MaximeEuziere on twitter.

Source

Copy-paste the code below into your address bar to run it. Unfortunately, making it compatible to the URL, the size of the app explodes to 1560 characters.

data:text/html,