Skip to content

Instantly share code, notes, and snippets.

@mark-adams
mark-adams / test_1.py
Created May 6, 2016 02:03
List ordering performance comparison
def test_1():
buf = []
for i in range(1000):
buf.append(i)
buf.reverse()
@mark-adams
mark-adams / lift_json.rb
Created November 30, 2015 05:12
A handy fluentd filter for lifting out nested json log messages from Docker logs.
module Fluent
class LiftJsonFilter < Filter
Fluent::Plugin.register_filter('lift_json', self)
def filter(tag, time, record)
begin
record = record.merge JSON.parse(record['log'])
record.delete 'log'
rescue Exception
end
@mark-adams
mark-adams / gpg-agent.conf
Last active August 29, 2015 14:12
Modified gpg-agent upstart script for Ubuntu 14.10 so that it properly sets ssh-agent environment variables
# This modified version of the gpg-agent.conf script should replace the version in
# /usr/share/upstart/sessions/ on Ubuntu 14.10
#
# Description: Sets SSH_AUTH_SOCK and SSH_AGENT_PID global environment variables if SSH
# support is enabled in the gpg-agent configuration.
#
# Suggested it as a patch to Ubuntu's gpg2 package via
# https://code.launchpad.net/~kramsmada/ubuntu/vivid/gnupg2/1407513-gpg-agent-set-ssh-env-vars/+merge/245538
#
@mark-adams
mark-adams / target_sums.js
Created December 23, 2014 18:06
Target Sums: A great interview programming problem with O(n^2) and O(n) solutions
/*
* Target Sums: Given a distinct list of unordered integers and an integer known as the target
* sum, devise a function that outputs true if some combination of two numbers from the list can
* add up to the target sum. Otherwise, return false.
*/
// This solution is the typical brute force that executes in O(n^2)
// n = arr.length
function targetSums(arr, target) {
@mark-adams
mark-adams / fib.py
Created December 23, 2014 18:03
Fibonacci functions: An Overview of Algorithmic Complexity
# This guy runs in linear O(n) time. That is good but its somewhat complex
def fib(n):
if n == 0 or n == 1: # 1
return 1
lastNum = 1 # 1
currentNum = 1 # 1
idx = 1 # 1
@mark-adams
mark-adams / setup-sltc-ca.py
Last active August 29, 2015 14:11
Docker Setup for SimpleLTC CA
#!/usr/bin/env python2
import textwrap
import os
ca_dir = '/etc/docker/certs.d/docker.sltc.local'
ca_cert = '''-----BEGIN CERTIFICATE-----
MIIDjDCCAnSgAwIBAgIQDlz2BfGJBr9MRgvOLbrKrDANBgkqhkiG9w0BAQUFADBO
MRUwEwYKCZImiZPyLGQBGRYFbG9jYWwxGTAXBgoJkiaJk/IsZAEZFglTaW1wbGVM
VEMxGjAYBgNVBAMTEVNpbXBsZUxUQy1Sb290LUNBMB4XDTEwMTIyODIyMDMyNVoX
@mark-adams
mark-adams / aes_example.cs
Created December 12, 2014 15:02
AES String Encryption (CBC) Example Code for C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace aes_example
{
using System;

Keybase proof

I hereby claim:

  • I am mark-adams on github.
  • I am kramsmada (https://keybase.io/kramsmada) on keybase.
  • I have a public key whose fingerprint is A18A 7DD3 283C CF2A B0CE FE0E C7A0 5E3F C972 098C

To claim this, I am signing this object:

@mark-adams
mark-adams / data_struct_examples.py
Created December 12, 2013 22:54
Some example python data structures
print 'Storing data using Lists!'
# Notice there are three lists
names = ['Bob', 'Phil', 'Dave']
addresses = ['123 Happy Ln.', '456 Mtn. Rd.', '1000 Century Dr.']
phones = ['111-111-1111', '222-222-2222', '333-333-3333']
# To access data about a person, you reference the same index in all three lists
print '{0} {1} {2}'.format(names[0], addresses[0], phones[0])
print
@mark-adams
mark-adams / letters.py
Last active December 21, 2015 04:59
A simple generator that returns a incrementing string of characters a-z, aa-zz, aaa-zzz, etc.
import itertools
import string
import math
default_alphabet = string.uppercase
def product_depth_first(alphabet=default_alphabet):
alphabet_list = [alphabet]