Skip to content

Instantly share code, notes, and snippets.

View orvn's full-sized avatar
🤩

orun orvn

🤩
View GitHub Profile
@orvn
orvn / hex-string.js
Created February 5, 2024 23:26
A converter for text to hexadecimel, and back to text (supports all unicode characters). Useful for places where base64 isn't usable, or doesn't support non-ascii characters.
function strToHex(str) {
return Array.from(str).map(char =>
char.codePointAt(0).toString(16).padStart(4, '0')
).join('');
}
function hexToStr(hex) {
let result = '';
for (let i = 0; i < hex.length; i += 4) {
result += String.fromCharCode(parseInt(hex.substring(i, i + 4), 16));
@orvn
orvn / npm-symlink.sh
Last active November 9, 2023 19:34
A shell script that forces symlinks to be created within a workspace (package) of an npm monorepo, so that `node_modules` in the repo root are referenced symbolically in the workspace's `node_modules`. This script can be run by the CI or a build script to forcefully ensure workspaces know about dependencies available in the repo root. It's a bi…
@orvn
orvn / notion-emails.gs
Created August 5, 2023 02:27
Organize Notion notification emails with Google Apps Script
function countMentionAndCommentEmails() {
var query = 'from:notify@mail.notion.so is:unread';
var start = 0;
var max = 200;
var allThreads = [];
while (true) {
var threads = GmailApp.search(query, start, max);
if (threads.length === 0) {
break;
@orvn
orvn / aggregate-gmail-unreads.gs
Created June 20, 2023 01:53
Aggregate Gmail unreads by sender using Google Apps Script
/**
*** Aggregate Gmail Unreads
***
*** A Google Apps Script for counting and sorting through unread emails
*** Works for both Gmail and Google Apps aka GSuite aka Google for Work aka Google Workspace
*** ES5 syntax must be used for .gs files, do not use ES6 or higher notation
***
*** Usage: go to script.google.com, create a new project, save and run this script, authenticate, and wait (< 6 minutes)
***
**/
@orvn
orvn / prepare_workspace.sh
Created January 23, 2022 17:34
Xcode ScummVM initialization
#!/bin/bash
LIBS_ZIP_URL="http://bsr43.free.fr/scummvm/ScummVM-iOS-libraries.zip"
GIT_REPO_URL="https://github.com/scummvm/scummvm.git"
# Clone the repository
git clone "$GIT_REPO_URL"
# Compile create_project
(cd scummvm/devtools/create_project/xcode; xcodebuild)
@orvn
orvn / htaccess-flag-reference.md
Created July 7, 2021 05:42
.htaccess Rewrite rule flags

Apache flags, sorted by frequency of use (more common at the top)

R

  • Perform an HTTP redirect
  • Default is a temporary 302 redirect
  • Always use with an L
  • e.g., [L,R=301]

L

  • Break if the rule matches, i.e. don't process subsequent rules
@orvn
orvn / redirect-attachment.php
Last active May 10, 2022 07:36
Wordpress redirect attachment page to parent
<?php
// Redirect an attachment page to its parent. Opening the actual attachments is still valid
add_action( 'template_redirect', 'void_attachment_parent', 1 );
if (!function_exists('void_attachment_parent')) :
function void_attachment_parent() {
global $post;
if ( is_attachment()):
// Optionally check file type and perform redirect for some files only.
@orvn
orvn / batch append newine
Created May 27, 2021 05:29
Sed append newline to all files that don't have one
#### Find and append a newline to all files that do not already have one
## Regular operation for most *nix
find ~/my-path/ -type f -exec sed -i -e '$a\' {} \;
## MacOS compatible sed
find ~/my-path/ -type f -exec sed -i '' -e '$a\' {} \;
## (for find commands, consider controlling the nesting level with max-depth)
@orvn
orvn / .vimrc
Last active July 28, 2023 01:32
A minimal and portablel vi configuration, to make CLI a little more usable. Additionally there are some comments at the bottom as reminders of important vi key bindings.
""" A minimal, portable vi configuration, use in ~/.exrc or ~/.vimrc """
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! ResetOsTheme()
" Detect current macOS theme
let l:os_theme = system("defaults read -g AppleInterfaceStyle 2> /dev/null")
" Adjust Vim settings based on macOS theme
if l:os_theme == "Dark\n"
@orvn
orvn / wp_perms.sh
Created December 23, 2020 04:44
Correctly repair Wordpress permissions (Redhat, CentOS, Debian, Ubuntu, MacOS, etc.)
#!/bin/bash
#
# run with:
# ./wp_perms.sh {path}
#
OWNER=apache # Wordpress owner, or the user that runs php. On CentOS/Redhat this is usually apache. On Ubuntu/Debian, this could be www-data
GROUP=apache # Configure your own group, or use the group from the user above (apache, www-data, etc.)
ROOT=$1 # Specify path when invoking this script
# Reset permissions to defaults