Skip to content

Instantly share code, notes, and snippets.

@bdargan
bdargan / gist:4334059
Created December 19, 2012 03:10
select random rows from various databases
There are lots of ways to select a random record or row from a database table. Here are some example SQL statements that don't require additional application logic, but each database server requires different SQL syntax.
Select a random row with MySQL:
SELECT column FROM table
ORDER BY RAND()
LIMIT 1
Select a random row with PostgreSQL:
SELECT column FROM table
@bdargan
bdargan / manual_encrypt.sh
Last active December 16, 2022 07:25
Manually encrypt files with openssl.
#!/bin/bash
rm -f content
rm *.enc
rm *.pem
rm keyfile
rm *.b64
rm *.dec
echo "generate: data-key for this content transfer"
@bdargan
bdargan / dotfile-init.zsh
Created December 8, 2021 10:15
dot file init
#setup dotfiles using a git bare repo, as per https://news.ycombinator.com/item?id=11071754
git init --bare $HOME/.dotfiles
alias dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
dotfiles config --local status.showUntrackedFiles no
echo "alias dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'" >> $HOME/.aliases

Sublime Text 2 - Useful Shortcuts

Tested in Mac OS X: super == command

Open/Goto


  • super+t: go to file
  • super+ctrl+p: go to project
  • super+r: go to methods
@bdargan
bdargan / aws-assumerole
Last active September 6, 2019 05:08
aws cli - assume role with MFA with cross-account support
#!/usr/bin/env zsh
#echo "This script depends on correctly configured aws credentials file. \n1. profile, \n2. dest_profile, contains role_arn in dest_account and refers creds to the source_profile, \n3. source_profile contains sts temporary credentials"
echo "1. Authenticate with current AWS_PROFILE (${AWS_PROFILE}) - please provide your account Id and iam username and your MFA token"
echo "2. Assume role as configured in ~/aws/.credentials#${DEST_PROFILE=DEST_PFOFILE}"
if [ -z `which jq` ]; then
echo "ERROR: required command:'jq' command line JSON processor - https://github.com/stedolan/jq"
exit 1
fi
@bdargan
bdargan / aws-policy-user-self-manage-mfa.json
Last active November 1, 2018 04:33
AWS policy for user to self manage credentials and mfa
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowIndividualUserToSeeAndManageTheirOwnAccountInformation",
"Effect": "Allow",
"Action": [
"iam:ChangePassword",
"iam:CreateAccessKey",
"iam:CreateLoginProfile",
@bdargan
bdargan / geocitylite_to_es.py
Last active April 11, 2017 11:30
load maxmind geocitylite db into elasticsearch
#! /usr/bin/env python
import json
import datetime
import httplib2
import re
import csv
import sys
http = httplib2.Http()
@bdargan
bdargan / frequently missed considerations in d2d ops or design.md
Last active October 4, 2016 22:08
Start gathering a list of things I know and experience that could be considered frequently missed considerations in design or day to day ops

draft Checklist of frequently missed considerations in design/d2d ops

starting another checklist of this stuff.

uncommon occurrences

  • daylight savings time switch
@bdargan
bdargan / stuff.el
Last active December 28, 2015 20:29
stuff, like curl and date utils find a number, that looks like a recent number of secs since the epoch and make it human readable
(defun epoch-to-iso ()
(interactive)
(re-search-forward "\\([0-9]\\{10,13\\}\\)")
(goto-char (match-beginning 0))
(replace-match (format-time-string "%Y-%m-%d" (seconds-to-time (/ (string-to-int (match-string 1)) 1000))))
)
(defun curl-something (begin end)
(interactive "r")
(shell-command (concat "curl " (buffer-substring begin end))))
@bdargan
bdargan / gist:7310769
Created November 4, 2013 23:00
password/entropy checkers
https://www.grc.com/haystack.htm
http://rumkin.com/tools/password/passchk.php
http://readablepassphrase.codeplex.com/