Skip to content

Instantly share code, notes, and snippets.

@lyoshenka
lyoshenka / search-git-history.md
Last active April 26, 2024 23:16
Search Git commit history for a string and see the diffs

Searching Git commit history

This should be one of the core features of Git, but for some reason it's impossible to figure out how to search for a string in your commit history and see the diffs that that string is in. Here's the best I've come up with:

To find which commits and which files a string was added or removed in:

git log -S'search string' --oneline --name-status

To see the diff of that

How not to rm yourself

Copied from https://github.com/sindresorhus/guides/blob/master/how-not-to-rm-yourself.md

The rm command is inherently dangerous and should not be used directly. It can at worst let you accidentally remove everything. Here's how you can protect you from yourself.

Use trash

The trash command-line tool will move stuff to the trash instead of permanently deleting it. You should not alias rm to trash as it will break external scripts relaying on the behavior of rm. Instead use it directly: trash image.jpg.

@lyoshenka
lyoshenka / ssl_oneline.sh
Created June 23, 2014 13:31
One-liner to create a self-signed SSL cert
#!/bin/bash
# http://stackoverflow.com/questions/10175812/how-to-build-a-self-signed-certificate-with-openssl
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 10000
# if you don't want a password for your cert
openssl genrsa -out key.pem 4096 && openssl req -x509 -new -nodes -key key.pem -out cert.pem -days 10000 -subj "/CN=DOMAIN"
@lyoshenka
lyoshenka / ngrok-selfhosting-setup.md
Last active February 1, 2024 20:14
How to setup Ngrok with a self-signed SSL cert

Intro

The plan is to create a pair of executables (ngrok and ngrokd) that are connected with a self-signed SSL cert. Since the client and server executables are paired, you won't be able to use any other ngrok to connect to this ngrokd, and vice versa.

DNS

Add two DNS records: one for the base domain and one for the wildcard domain. For example, if your base domain is domain.com, you'll need a record for that and for *.domain.com.

Different Operating Systems

@lyoshenka
lyoshenka / ddns.sh
Last active October 11, 2023 04:28 — forked from kevinoconnor7/c-ddns.sh
Quick and dirty DDNS using Bash and Cloudflare (API v4 compatible)
#!/usr/bin/env bash
# Step 1: Fill in EMAIL, TOKEN, DOMAIN and SUBDOMAIN. Your API token is here: https://dash.cloudflare.com/profile/api-tokens
# Make sure the token is the Global token, or has these permissions: #zone:read, #dns_record:read, #dns_records:edit
# If you want to set the root domain instead of a subdomain, set SUBDOMAIN to "@"
# Step 2: Create an A record on Cloudflare with the subdomain you chose
# Step 3: Run "./ddns.sh -l" to get the zone_id and rec_id of the record you created.
# Fill in ZONE_ID and REC_ID below
# This step is optional, but will save you 2 requests every time you run this script
# Step 4: Run "./ddns.sh". It should tell you that record was updated or that it didn't need updating.
@lyoshenka
lyoshenka / coding_maxims.md
Last active August 23, 2023 21:18
Keep this in mind
@lyoshenka
lyoshenka / pre-push.sh
Last active June 14, 2023 06:55 — forked from greglboxer/pre-push.sh
Git pre-push hook to prevent force-pushing or deleting a special branch (e.g. master)
#!/bin/bash
# Requires git 1.8.2 or newer
# Prevents force-pushing or deleting a special branch (e.g. master).
# Based on: https://gist.github.com/pixelhandler/5718585 and https://gist.github.com/stefansundin/d465f1e331fc5c632088
# Install:
# cd path/to/git/repo
# curl -fL -o .git/hooks/pre-push https://gist.githubusercontent.com/lyoshenka/158cfff41d09e1dcf029/raw/pre-push.sh
# chmod +x .git/hooks/pre-push
#!/bin/bash
####
# Split MySQL dump SQL file into one file per table
# based on http://blog.tty.nl/2011/12/28/splitting-a-database-dump
####
if [ $# -ne 1 ] ; then
echo "USAGE $0 DUMP_FILE"
fi
@lyoshenka
lyoshenka / pinboard-rename-tag.php
Created September 15, 2013 00:57
Merge two Pinboard tags into one, or rename a tag.
#!/usr/bin/env php
<?php
if (!isset($argv[2]))
{
echo "${argv[0]} FROM TO\n";
exit(1);
}
include 'pinboard-api.php'; // https://github.com/kijin/pinboard-api
@lyoshenka
lyoshenka / example.rb
Created January 31, 2013 04:47 — forked from mislav/example.rb
Example of outputting YAML in Ruby using inline style (array is all on one line, not spread out with each element on its own line)
full_data = {
response: {body: StyledYAML.literal(DATA.read), status: 200},
person: StyledYAML.inline('name' => 'Steve', 'age' => 24),
array: StyledYAML.inline(%w[ apples bananas oranges ])
}
StyledYAML.dump full_data, $stdout
__END__
{