Live data from Hacker News

Ask HN: Small scripts, hacks and automations you're proud of?

news.ycombinator.com

151–160 of 340 posts

Re: Ask HN: Small scripts, hacks and automations you're proud of?

#151
A simple diary script.

`$ diary` to create/open a file for today's diary in vim: https://github.com/Aperocky/diaryman/blob/master/diaryman.sh

Or try `pip install diarycli`: https://github.com/Aperocky/diarycli, for a pip packaged python version that does the exact same thing.

I've actually kept diary and work logs, things I did not know I was capable of.

Re: Ask HN: Small scripts, hacks and automations you're proud of?

#152
I don't remember the exact script, but once had a shit temp job doing QA on standardized test software. Basically, Here's the answers, take the test and make sure it doesn't fuck up somehow. Used autohotkeys in a way that I could do 80% of my workload with only 4 keys of keyboard. (Multiple choice test). It was basically just abcd then a bunch of tabs and shift + tabs to navigate through the otherwise tedious UI. I considered bringing in a guitar hero controller and mapping them to that, but got fired for sitting on my desk before I had the chance.

Why it was even nessecary to dothis in the first place rather than a script that also entered the correct answer was presumably some weird thing in the contract with the state who administered the test.

Re: Ask HN: Small scripts, hacks and automations you're proud of?

#153

This tiny script keeps my gmail inbox clean and manageable. It auto-archives any emails older than 2 days (you can change this obviously) unless they're starred - this changes my email experience in two ways: 1) My email inbox ONLY has emails that are either new or that I decided were relevant. I have two days to notice this. 2) When I'm scanning my email, if I see something important that I don't have time to deal w…

Oh man this is cool, i would definitely want to delete certain mail after a week or so like the subscribed news or mail notifications.

Re: Ask HN: Small scripts, hacks and automations you're proud of?

#154
I can't even remember the year this started but it was definitely what got me into coding.

Virus that turned files and folders on removable drives into hidden system files was a popular thing that antivirus progs just didn't help with was everywhere. Friend's and co-workers would constantly bombard me for help recovering the files. When I figured out essentially how the pesky virus worked (this was before the variants that made reg edits) I coded something to do the opposite in a batch script. Would then just set it to identify the portable drive added and it'd delete the virus....the .lnk shortcut files it created and then unhide and return the folders and files back to normal.

Nothing fancy but it did influence my career direction alot.

Re: Ask HN: Small scripts, hacks and automations you're proud of?

#155
I usually check weather on forecast.gov website, with these bookmarked urls:

https://forecast.weather.gov/MapClick.php?lat=40.7983&lon=-1...

The issue I had with these were that, these pages are always in desktop mode even on mobile. So i made a one page static website which takes & stores these urls in local storage, & fetches the one I click upon. On next pageload, it remebers the last loaded city & it loads it again.

All the page is in mobile-first view mode in css.

https://spa.bydav.in/weather/index.html

You might see nothing as you need to preload/populate the local storage with either manually copied urls or simply paste this json.

  [
  {
    "abb": "SNR",
    "full": "Sonora",
    "url": "https://forecast.weather.gov/MapClick.php?lat=37.98&lon=-120.38&unit=0&lg=english&FcstType=json&TextType=1"
  },
  {
    "abb": "RDB",
    "full": "Red Bluff",
    "url": "https://forecast.weather.gov/MapClick.php?lat=40.1781&lon=-122.2354&unit=0&lg=english&FcstType=json&TextType=1"
  },
  {
    "abb": "SFO",
    "full": "San Francisco",
    "url": "https://forecast.weather.gov/MapClick.php?lat=37.7771&lon=-122.4197&unit=0&lg=english&FcstType=json&TextType=1"
  },
  {
    "abb": "ERK",
    "full": "Eureka",
    "url": "https://forecast.weather.gov/MapClick.php?lat=40.8033&lon=-124.1595&unit=0&lg=english&FcstType=json&TextType=1"
  }
]

Re: Ask HN: Small scripts, hacks and automations you're proud of?

#156
I've done three worth mentioning.

One is GenFortune: https://github.com/EternityForest/GenFortune Which is like fortune, but it generates them using a MadLibs style algorithm from data files.

One is a candle flicker simulation algorithm. I did not make this demo, I wrote the original for the PIC, they adapted a version of it for JS: http://blackdice.github.io/Candle/

At the time cheap LED candles weren't very good, but it seems many are a lot better now. I used a model assuming that the flickering was wind driven, that the flame always wants to rise towards it's maximum at a certain rate, but that depending on the current wind speed at any time it can get randomly "toppled" to a lower value, while then wind settles down to a baseline but can randomly jump up in a gust to a higher speed.

Of course, now we have multicolor multipixel flame algorithms that do way better, but this is pretty good on a single pixel light.

I still use mostly the same algorithm for DMX flame effects in Python, but I apply then effect less to the red channel so it gets redder when the light goes down for a little added variety.

The other is this RNG. It does not even have a full period for it's 32 bits of state but it's very fast on PIC10 type chips. I can't think of any reason I'd use it. I was like 15. But of everything I've ever made, this gets the most attention, and I'm not entirely sure why. It doesn't even pass all statistical tests. I'd probably use it over LCG though.

``` uint8_t x,a,b,c; uint8_t randRNG8() // Originally unsigned char randomize(). { x++; //x is incremented every round and is not affected by any other variable a = (a^c^x); //note the mix of addition and XOR b = (b+a); //And the use of very few instructions c = ((c+(b>>1))^a); //the right shift is to ensure that high-order bits from b can affect return( c); //low order bits of other variables } ```

Re: Ask HN: Small scripts, hacks and automations you're proud of?

#158
The Apple Watch doesn't have a good built-in note-taking app, for a long while much to my annoyance. But it turns out the reminders function works great for taking voice notes. So I wrote an AppleScript (of all things) to scrape the reminders app for all the voice notes I take when I'm out. I use this every day and this little script has brought me such peace and joy.

https://gist.github.com/michaelterryio/478f5b93111f5f5fc57c0...

To practice my marketing copy, I wrote a not-for-profit one page site about how I use it:

https://drivingwithworkflowy.com/

Re: Ask HN: Small scripts, hacks and automations you're proud of?

#159

Most useful script I've ever written, and legitimately how I keep track of everything important in my life: #! /bin/bash function todo { if [ $# -eq 0 ] then vim ~/Dropbox/todo/todo_list.txt else vim "$HOME/Dropbox/todo/todo_list_$1.txt" fi } Sourcing this in my shell means I just have to type... todo To automatically get into my default todo list which is synced to dropbox (and thus accessible everywhere on mobile a…

I use Org mode in Emacs, so I have a follow up:

Do you have a format in your text files to track when things are done, like a checklist?

In Org, you can give things states like "TODO", "INPROGRESS", "DONE", "CANCELLED", add checkboxes (like "[ ]" and "[x]"), have sub-tasks/lists, etc.

I have really gotten into Org, and I have found there are a few other checklist formats/programs in plain text. Just wondering how you do it.

Re: Ask HN: Small scripts, hacks and automations you're proud of?

#160
A small workflow that I come back to all the time is generating curl commands with dynamic values through SQL queries to run something against our API. People don't always think about that so once you have it in your tool belt it's a great tool you'll reach to often.

Something like the following, then just copy it in a shell script, chmod +x it and execute it:

    select 'curl -XPOST localhost:9090/apis/some-service/' || p.technical_name || '/locale/' || l.full_locale
Post reply on HN