Skip to content

Instantly share code, notes, and snippets.

View SimplGy's full-sized avatar

Eric Miller SimplGy

View GitHub Profile
@SimplGy
SimplGy / renameToHash.sh
Last active July 27, 2023 07:30
Rename files with a hash based on their contents. eg: `abc.jpg` to `3101ace8db9f.jpg`. Useful for detecting duplicates.
#!/bin/bash
# TODO: skip tiny files (so small they couldn't be photos)
# TODO: make sure sym links and other file system oddities are handled
# TODO: look at paralellization for perf boost
#
# Constants
#
CHAR_COUNT=12
BLOCK_COUNT=6
@SimplGy
SimplGy / audio_from_elevenlabs.js
Created May 22, 2023 00:36
works, but only for short strings. getting 400 on anything else.
// docs:
// https://docs.elevenlabs.io/api-reference/quick-start/introduction
// https://api.elevenlabs.io/docs#/text-to-speech/Text_to_speech_v1_text_to_speech__voice_id__post
const axios = require('axios');
const fs = require('fs');
const path = require('path');
require('dotenv').config();
// Name: Screenshot URL
import "@johnlindquist/kit"
const { chromium }: typeof import("playwright") = await npm(
"playwright"
)
// get URL from user
let urlFromUser = await arg("Enter the URL to screenshot");
// Name: today-timestamp
// Description: inserts today's date in "ISO" format 2023-02-11
// Snippet:
import '@johnlindquist/kit';
function twoDigits(number: number): string {
return number.toString().padStart(2, '0');
}
import "@johnlindquist/kit"
// Menu: Giphy
// Description: Search giphy. Paste link.
// Author: John Lindquist
// Twitter: @johnlindquist
let download = await npm("image-downloader")
let queryString = await npm("query-string")
@SimplGy
SimplGy / anchorize-jekyll-headings.js
Last active October 31, 2022 17:20
For every heading in your page, this adds a little anchor link `#` that you can click to get a permalink to the heading. No dependency on jQuery or anything else. Requires that your headings already have an `id` attribute set (because that's what jekyll does)To use it, just drop it in the layout you use for your blog pages. You can style `.deepL…
(function(){
'use strict';
/*
Create intra-page links
Requires that your headings already have an `id` attribute set (because that's what jekyll does)
For every heading in your page, this adds a little anchor link `#` that you can click to get a permalink to the heading.
Ignores `h1`, because you should only have one per page.
The text content of the tag is used to generate the link, so it will fail "gracefully-ish" if you have duplicate heading text.
*/
@SimplGy
SimplGy / addFileToGit.js
Last active October 6, 2021 12:38
Usage: `addFileToGit(foo.txt, "some file contents")`. Uses the "octokit" to add a single file to your gitub repo. Adapted from a Ruby guide by http://mattgreensmith.net
const Octokit = require('@octokit/rest'); // https://octokit.github.io/rest.js/
// Customize this stuff:
const auth = 'your-key-generated-in-github-ui'; // PRIVATE!
const owner = 'repo-owner';
const repo = 'your-repo-name';
// Constants
const userAgent = 'git commiter v1';
const ref = 'heads/master';
@Injectable({providedIn: 'root'})
export class ExternalUrlService implements CanActivate {
canActivate({ data }: ActivatedRouteSnapshot): boolean {
window.open(data.externalUrl, '_blank');
return false;
}
}
@SimplGy
SimplGy / generate-nginx-config.js
Last active August 13, 2021 20:53
script that makes an nginx config for every folder in a certain dir
const { readdirSync, statSync, writeFileSync } = require('fs')
const { join } = require('path')
// ----------------------------------------- Config
const DIR = '/home/deploy/www';
const TARGET = '/home/deploy/deployNginxConfig';
const HEADER = `
# Config generated by 'generate-nginx-config.js', do not hand-edit
@SimplGy
SimplGy / generate-index-from-config.js
Created August 3, 2020 01:46
For every website folder that contains a certain file, autogen an index.html landing page for it.
// For every website folder that contains a certain file, autogen an index.html landing page for it.
const { readdirSync, statSync, writeFileSync, existsSync, readFileSync } = require('fs');
const { join } = require('path');
// ----------------------------------------- Config
const DIR = '/home/deploy/www';
const CONFIG_FILE = 'logo/info.txt';