Skip to content

Instantly share code, notes, and snippets.

View mercul3s's full-sized avatar
🐓
Code Farming

Mercedes Coyle mercul3s

🐓
Code Farming
View GitHub Profile
@mercul3s
mercul3s / lost_and_found.py
Last active August 29, 2015 13:57
This is an example of looping through a dictionary in Jinja syntax, storing all the items in the dictionary in fields in a table. The table header rows are created outside of the loop, and the fields are created inside the for loop for each item in the dictionary. You can do the same thing with a list of objects by using syntax such as item.item…
# Here's how the controller route and function look:
@app.route("/search_items", methods=["POST"])
def search_items():
search_terms = form.search.data
results = search(search_terms) # search is a function I've defined in another file and imported
return render_template("search_results.html", search_res=results)
@mercul3s
mercul3s / layout.html
Created March 28, 2014 20:31
A code snippet describing how to use Flask's Session object for user information.
<!DOCTYPE html>
<!-- layout.html -->
<html>
<head>
</head>
<body>
<div class="container">
<div id='nav'>
<a href='{{ url_for('index') }}'><img src="/static/images/monitor-head.png" width='60px' height='31px' alt='monitor-head' id='head-logo' /></a>
<ul id='nav-bar'>
@mercul3s
mercul3s / ssh-host-color.sh
Created June 21, 2014 16:33
SSH host colors
#!/bin/sh
#
# ssh into a machine and automatically set the background
# color of Mac OS X iTerm depending on the hostname.
#
# Installation:
# 1. Save this script to /your_script_location/ssh-host-color.sh
# 2. chmod 755 /your_script_location/ssh-host-color.sh
# 3. alias ssh=/your_script_location/ssh-host-color.sh (add this to .bash_profile)
# 4. Configure your host colors below.
# Git branch in prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "
HISTFILESIZE=5000
alias ssh=~/dev/Scripts/ssh-host-color.sh
@mercul3s
mercul3s / gist:56d73cb74ed71bf0813e
Created September 3, 2014 20:34
Example dashing job for elasticsearch cluster health
require 'elasticsearch'
# defaults to "localhost"
client = Elasticsearch::Client.new log: true
SCHEDULER.every '5s', :first_in => 0 do |job|
health = client.cluster.health
send_event('es_health', {value: health['status']})
end
@mercul3s
mercul3s / .bash_profile
Last active March 15, 2018 19:43
rainbow bash prompt
# Bash Prompt Color Variables
blu="\[\033[34m\]"
cyn="\[\033[36m\]"
grn="\[\033[32m\]"
yel="\[\033[33m\]"
red="\[\033[31m\]"
pur="\[\033[35m\]"
gry="\[\033[37m\]"
end="\[\033[00m\]"
@mercul3s
mercul3s / Phant_Ethernet.ino
Created December 6, 2015 23:28
Sparkfun Ethernet Example
/*****************************************************************
Phant_Ethernet.ino
Post data to SparkFun's data stream server system (phant) using
an Arduino and an Ethernet Shield.
Jim Lindblom @ SparkFun Electronics
Original Creation Date: July 3, 2014
This sketch uses an Arduino Uno to POST sensor readings to
SparkFun's data logging streams (http://data.sparkfun.com). A post
will be initiated whenever pin 3 is connected to ground.
@mercul3s
mercul3s / exercise.sh
Last active April 18, 2016 17:22
Motivator for exercise in my day
#!/bin/bash
# Pick a random mac voice out of the list below, and then pick a random action to say.
voices=(
Alex
Bells
Bruce
Cellos
Daniel
Fiona
@mercul3s
mercul3s / com.mercmotivator.cron.plist
Created March 15, 2016 20:44
plist for exercise.sh
<!--
To use this plist file, edit the string (name), and save it to ~/Library/LaunchAgents.
Make sure the file is owned by root. To start the plist, enter the following commands:
sudo launchctl load com.mercmotivator.cron.plist
And you're done! The plist will now run autmatically every 30 minutes, unless you decide
to change the time interval.
-->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
@mercul3s
mercul3s / unique-list.go
Last active October 30, 2017 23:06
Determining unique values in a slice or array in Go requires the use of a map.
package main
import (
"fmt"
)
func appendUnique(list []string) []string {
// initialize a map of string keys and boolean values for
// keeping track of list entries we've seen.
uniqueKeys := make(map[string]bool)