Skip to content

Instantly share code, notes, and snippets.

@idealwebsolutions
idealwebsolutions / zw-utils.js
Created December 10, 2021 06:03
some zero width functions
function textToZeroWidth (text, encoding = 'utf8') {
const buf = Buffer.from(text, encoding);
return buf.reduce((str, byte) => str + byte.toString(2).padStart(8, '0'), '')
.split('').map((binary) => binary === '0' ? '​' : '‌').join(' ');
};
function zeroWidthToText (zwChars) {
let message = '';
const b = zwChars.map((zw) => zw === '​' ? '0' : '1').join('');
for (let x = 0; x < Math.ceil(b.length / 8); x++) {
@idealwebsolutions
idealwebsolutions / lsb.py
Last active July 28, 2021 00:12
basic stego lsb to hide a plaintext message in a png image using a null term to determine end
#!/usr/bin/python3
from PIL import Image
NULL = 00000000
def string_bin(text):
return ''.join(['{:08b}'.format(ord(c)) for c in text])
def spl_bin(binary):
#!/usr/bin/env python
from requests import get
from lxml.html import fromstring
from base64 import b64decode
from re import search
def _get_page_content(url):
""" Fetches page content
@idealwebsolutions
idealwebsolutions / tts.sh
Last active February 24, 2021 08:03
Streamlabs TTS one liner to disk
#!/bin/env bash
curl -s -d '{"voice": "'"$1"'", "text": "'"$2"'"}' -H "Content-Type: application/json" -H "Context-Type: application/json" https://streamlabs.com/polly/speak | jq -r '.speak_url' | xargs curl -s -0 --output - | ffmpeg -y -i pipe:0 -vn -acodec copy "$3.ogg"
@idealwebsolutions
idealwebsolutions / selection.js
Created August 3, 2018 20:50
(Old) Selection sort
function selectionSort(array) {
for (var i = 0; i < array.length - 1; i++) {
for (var j = i + 1; j < array.length; j++) {
if (array[i] > array[j]) {
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
@idealwebsolutions
idealwebsolutions / bubble.js
Last active August 2, 2018 22:42
(Old) Naive bubblesort
function bubbleSort(array) {
var swapped = true;
// Iterate until swaps no longer occur
while (swapped) {
// Assume swaps no longer needed
swapped = false;
// Iterate entire array
for (var i = 0; i < array.length; i++) {
var next = array[i - 1];
var cur = array[i];
@idealwebsolutions
idealwebsolutions / morse.lua
Last active August 1, 2020 18:38
Morse code script for Weechat
local SCRIPT_NAME = 'morse'
local SCRIPT_AUTHOR = 'unaffiliated <alex@unaffiliated.site>'
local SCRIPT_VERSION = '1'
local SCRIPT_LICENSE = 'GPL3'
local SCRIPT_DESC = 'Morse code translator'
-- International Morse Alphabet (ITU)
local MORSE = {
a = ".-",
b = "-...",
@idealwebsolutions
idealwebsolutions / ps.sh
Last active September 16, 2024 02:40
Price spot endpoints for ETH and BTC using Coinbase API v2 (no auth required)
# Endpoints for Coinbase API
curl -s https://api.coinbase.com/v2/prices/eth-usd/spot -H 'CB-VERSION: 2015-04-08' | jq -r ".data.amount" | sed -E 's/(.+)/$\1/'
curl -s https://api.coinbase.com/v2/prices/btc-usd/spot -H 'CB-VERSION: 2015-04-08' | jq -r ".data.amount" | sed -E 's/(.+)/$\1/'
# Endpoints for Gemini Ticker API
curl -s https://api.gemini.com/v1/pubticker/ethusd | jq -r 'select(.ask != null)' | sed -E 's/(.+)/$\1/'
curl -s https://api.gemini.com/v1/pubticker/btcusd | jq -r 'select(.ask != null)' | sed -E 's/(.+)/$\1/'
@idealwebsolutions
idealwebsolutions / palindrome.js
Created March 9, 2017 08:39
Basic palindrome (cheating way)
function checkPalindrome(inputString) {
return inputString === inputString.split('').reverse().join('')
}
@idealwebsolutions
idealwebsolutions / century.js
Created March 9, 2017 08:36
Get century from year
function centuryFromYear(year) {
return year % 100 === 0 ? Math.trunc(year / 100) : Math.trunc(year / 100) + 1
}