Skip to content

Instantly share code, notes, and snippets.

Strings

String.prototype.*

None of the string methods modify this – they always return fresh strings.

  • charAt(pos: number): string ES1

    Returns the character at index pos, as a string (JavaScript does not have a datatype for characters). str[i] is equivalent to str.charAt(i) and more concise (caveat: may not work on old engines).

@jmuspratt
jmuspratt / mediaName
Last active August 24, 2023 14:42
exiftool : rename files in current dir to YYYY-MM-DD-HH-MM-SS-1.ext
# Function for your .zshrc file
# Requirements: install the package manager Homebrew (http://brew.sh), then install exiftool (type brew install exiftool in Terminal.app).
# Renames image and MOV files according to EXIF capture date, using YYYY-MM-DD-HH-MM-SS.ext format.
# Files shot within the same second get copy number added (-1,-2, etc.).
# Video files require a different, so we run exiftool 3 times:
# 1. Exclude MOV files and rename the image files with <CreateDate>.
# 2. Target MOV files and rename them with MediaCreateDate (for iPhone videos).
# 3. Target MOV files and rename them with DateTimeOriginal (for Fuji camera videos).
@lelandbatey
lelandbatey / whiteboardCleaner.md
Last active April 25, 2024 02:01
Whiteboard Picture Cleaner - Shell one-liner/script to clean up and beautify photos of whiteboards!

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"

Results

@ttscoff
ttscoff / speedmail.applescript
Last active December 8, 2023 22:00
Speed up Mail.app
(*
Speed up Mail.app by vacuuming the Envelope Index
Code from: http://www.hawkwings.net/2007/03/03/scripts-to-automate-the-mailapp-envelope-speed-trick/
Originally by "pmbuko" with modifications by Romulo
Updated by Brett Terpstra 2012
Updated by Mathias Törnblom 2015 to support V3 in El Capitan and still keep backwards compability
Updated by @lbutlr for V5 and Container folder in High Sierra and use du
*)
tell application "Mail" to quit
@ttscoff
ttscoff / luckyduck.rb
Created August 22, 2012 11:10
Get first web search result as Markdown link
#!/usr/bin/ruby
require 'net/http'
def e_url(string)
string.gsub(/([^a-zA-Z0-9_.-]+)/n) do
'%' + $1.unpack('H2' * $1.size).join('%').upcase
end
end
def do_search(phrase)
@CJKinni
CJKinni / archiveTweets.rb
Last active December 5, 2022 17:50
Download your twitter posts into a single markdown file
#!/usr/bin/ruby
=begin
This script turns downloadable tweets from twitter into a markdown
based text file timeline.
To run, change the 'Username' and 'TwitterFilename' below.
I THINK that this is all working. Check the previous gist version
for a more stable script with far fewer features. Let me know in the
@isaacs
isaacs / node-and-npm-in-30-seconds.sh
Last active March 8, 2024 02:11
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh