Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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__
{

Backtick.io - Save to Pinboard

#!/usr/bin/env python
# Clone or update all a user's gists
# curl -ks https://gist.githubusercontent.com/lyoshenka/de4d3a0e82d8be987d69/raw/gist-backup.py | python
# curl -ks https://gist.githubusercontent.com/lyoshenka/de4d3a0e82d8be987d69/raw/gist-backup.py | USERNAME=lyoshenka python
# USERNAME=lyoshenka python gist-backup.py
import json
import urllib
from subprocess import call
from urllib import urlopen
@lyoshenka
lyoshenka / unserialize.js
Last active December 21, 2018 09:39 — forked from brucekirkpatrick/jquery.unserialize.js
Takes a string in format "param1=value1&param2=value2" and returns an javascript object. The opposite of https://api.jquery.com/serialize
/**
* $.unserialize
*
* Takes a string in format "param1=value1&param2=value2" and returns an object { param1: 'value1', param2: 'value2' }. If the "param1" ends with "[]" the param is treated as an array.
*
* Example:
*
* Input: param1=value1&param2=value2
* Return: { param1 : value1, param2: value2 }
*
@lyoshenka
lyoshenka / maintenance.html
Last active October 17, 2017 22:40 — forked from pitch-gist/gist:2999707
Simple Maintenance Page
<!doctype html>
<html><head>
<meta charset="utf-8" />
<title>Site Maintenance</title>
<style type="text/css">
body { padding: 50px 30px 30px; font: 20px Helvetica, sans-serif; color: #222; line-height: 1.4 }
h1 { font-size: 40px; }
article { text-align: left; max-width: 650px; margin: 0 auto; }
a { color: #dc8100; padding: 3px }
a:hover { color: #fff; background-color: #dc8100 }
@lyoshenka
lyoshenka / passwordgen.sh
Last active May 17, 2016 13:26 — forked from linuxboytoo/passwordgen.sh
Bash Random Password Generator
#!/bin/bash
head -n100 /dev/urandom | strings | egrep -o '([a-zA-Z0-9#%&^])' | awk '{ORS=""; print $1}' | head -c 35; echo
@lyoshenka
lyoshenka / latency.txt
Created February 17, 2016 17:38 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD