Skip to content

Instantly share code, notes, and snippets.

@cahna
cahna / sub_palindrome.lua
Last active December 26, 2015 04:08
For a given string, find the longest palindrome that is a sub-string of the original string (ignoring whitespace)
#!/usr/bin/env luajit
local string = string
local socket = require 'socket'
--- Returns the character at index i (just some syntactic sugar for str:gsub(i,i))
-- @usage ('foobar'):c(3) == 'o' -- True
-- @string i Index of character within string
-- @returns Character at index i within string
function string:c(i)
@cahna
cahna / clever-one-liner.sh
Last active December 31, 2015 02:29
Clever: avg students/section (one-liner demo)
# Dependency: http://stedolan.github.io/jq/
jq '{total_districts: .[].count, students: [ .[][].data.students | length ]} | .total_students = reduce .students[] as $i (0; . + $i) | .total_students / .total_districts' <(curl -s -u DEMO_KEY: https://api.getclever.com/v1.1/sections) 2>/dev/null
@cahna
cahna / add-pathogen-submodules.sh
Last active March 3, 2017 11:13
manage installed pathogen plugins as git submodules within dofiles repo
# cd into your dotfiles repo and run this to add all of your
# installed pathogen plugins as submodules of your dotfiles repo:
ls ~/.vim/bundle \
| xargs -I% echo "grep -m1 -oP 'https[^\ ]+' <(cd ~/.vim/bundle/% && git remote -v show)" \
| bash \
| xargs -n1 git submodule add
@cahna
cahna / ENV.moon
Created July 6, 2014 09:24
Moonscript - read environment variable shorthand
-- Package that helper into the worlds shortest module.
-- Usage: import HOME, SHELL, EDITOR from require 'ENV'
setmetatable {}, __index: (k) => os.getenv k
@cahna
cahna / ansible-aur-pkg-installer.md
Last active September 11, 2022 06:26
download, build, and install aur packages with ansible

About

When using ArchLinux, I typically prefer to use an AUR helper like pacaur or yaourt to automate away the process of installing a community package.

Ansible's pacman module is great, but it doesn't support AUR packages or pacman's -U flag. Installing AUR packages with Ansible seemed to be left as an exercise to the user, and since AUR helpers do not come with a fresh Arch install, I

@cahna
cahna / proxy.py
Last active August 29, 2015 14:23
Simple Python Proxy
# -*- coding: ascii -*-
from webob.dec import wsgify
from wsgiproxy import HostProxy
from wsgiref.simple_server import make_server
@wsgify
def application(req):
return HostProxy('http://example.com')
@cahna
cahna / parse_ps_aux.py
Last active September 27, 2023 22:39
Parse the output of `ps aux` into a list of dictionaries representing the parsed process information from each row of the output.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import pprint
import subprocess
def get_processes():
"""
Parse the output of `ps aux` into a list of dictionaries representing the parsed
@cahna
cahna / verify_mysql_replication.py
Created December 29, 2016 18:04
Check that the contents of 2 databases are identical
#!/usr/bin/env python
import sys
import ConfigParser
import MySQLdb
import click
from threading import Thread
class MySQLExtrasFileParser(ConfigParser.ConfigParser):
@cahna
cahna / ansible-cli-wrapper.py
Last active July 28, 2022 00:00
Custom CLI wrapper for common ansible tasks.
#!/usr/bin/env python
#
# Run `python ansible-cli-wrapper.py -h` for usage information.
#
import os
from datetime import datetime
from tempfile import NamedTemporaryFile
import boto

Keybase proof

I hereby claim:

  • I am cahna on github.
  • I am cahna (https://keybase.io/cahna) on keybase.
  • I have a public key whose fingerprint is 7ED9 1182 506F D80C D50E 943D B3E5 2F13 A94F 8BEA

To claim this, I am signing this object: