Skip to content

Instantly share code, notes, and snippets.

View atheiman's full-sized avatar
😬

Austin Heiman atheiman

😬
View GitHub Profile
@atheiman
atheiman / README.md
Last active August 29, 2015 14:10
Simple Django

Single file Django project template from the O'Reilly book Lightweight Django.

Minimal, simplified, deployable, production ready Django app. 33 lines of Python.

Info

Django can be overwhelming when starting out. Most Django projects have a very large codebase broken into dozens of files, but the idea of this Gist is to show that it doesn't have to be large. Many of the components of the default django-admin.py startproject my_project project template are confusing to new users, so this project template only includes the minimum required settings to run an application with one url and one view.

Usage

@atheiman
atheiman / utils.js
Last active August 29, 2015 14:16
js-utils
function debug(logString) {
DEBUG = (typeof DEBUG === "undefined") ? true : DEBUG;
if (DEBUG)
console.log('DEBUG: ' + logString);
}
function checkArrayForDuplicates(array, arrayNameStr) {
// return false if no dups, return array of error strings if dups
// parameters:
// array | required | Array with potential duplicates
@atheiman
atheiman / get-zip.js
Created November 24, 2015 19:29
Get a client zip code using google maps api
window.navigator.geolocation.getCurrentPosition(function(pos){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
var regex = /(\d{5})",\s*.*postal_code/;
var matches = regex.exec(xhttp.responseText);
console.log('ZIP code:', matches[1]);
}
};
var url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' +
@atheiman
atheiman / chef_search_nodes.rb
Last active June 11, 2016 18:46
Chef Node Search API
require 'chef'
def config_chef
chef_config_env_var = 'CHEF_CONFIG'
if ENV[chef_config_env_var]
chef_config = ENV[chef_config_env_var]
else
default_chef_configs = ['~/.chef/knife.rb', '/etc/chef/client.rb']
default_chef_configs.each do |c|
if File.exists?(File.expand_path(c))
@atheiman
atheiman / call_parent_module_method.rb
Last active June 11, 2016 23:21
ruby call parent module (or parent class) method
def my_method
'out of module'
end
module MyMod
def self.my_method
'in module'
end
class MyClass

Messing around with knife exec

SEARCH='chef_environment:*dev*' knife exec partial_search.rb
# - name: node-a
#   hostname: node-a
#   fqdn: node-a.domain.net
#   ipaddress: 10.190.116.124
#   run_list:
# - role[base_os]
@atheiman
atheiman / README.md
Last active July 17, 2016 18:00
Deep merge hashes. If both values are numeric they are summed. (Ruby)

Deep merge hashes. If both values are numeric they are summed.

$ ruby deep_sum_merge.rb
source:
layer_1: 10
deeper:
  layer_2: 20
  deeper:
    layer_3: 30
 deeper:
rbenv versions
which bundle
bundle --help
@atheiman
atheiman / README.md
Last active October 10, 2016 20:56
apache_fun

Just messing around with parsing a log file with Ruby...

$ ruby apache_fun.rb
01:02:03 report
  2 INFO messages
  1 WARN messages
01:02:05 report
  2 ERROR messages
 1 INFO messages