Skip to content

Instantly share code, notes, and snippets.

@welbornprod
welbornprod / Embedded Python in BASH
Created August 14, 2014 23:22
A little trick to embed python code in a BASH script.
#!/bin/bash
# Here are some embedded Python examples using Python3.
# They are put into functions for separation and clarity.
# Simple usage, only using python to print the date.
# This is not really a good example, because the `date`
# command works just as well.
function date_time {
"""
Basic IRC bot using Twisted.
Code is by habnabit, and comes from https://gist.github.com/habnabit/5823693
"""
import sys
from twisted.internet import defer, endpoints, protocol, reactor, task
from twisted.python import log
from twisted.words.protocols import irc
@welbornprod
welbornprod / bash english definition command
Last active December 11, 2015 23:49
Show the definition of an english word in your BASH terminal. Works best as a BASH function, might need to install 'lynx' console browser. ... sudo apt-get install lynx
# BASH function (As of 08/13/14 this no longer works (they finally change the layout of the page.)
# It is kept here as a reference, in case someone wants to make a different version.
# ..mine is in Python now :)
function define() {
if [ "${1}" = "" ] ; then
echo "Usage: define dog"
else
lynx -dump -nonumbers -width=160 "http://dictionary.reference.com/browse/${1}" | grep -A15 "World English Dictionary"
fi
}
@welbornprod
welbornprod / bash spanish translation command
Created January 31, 2013 02:44
Translate english word to spanish in your BASH terminal. Works best as a BASH function, might have to install 'lynx' console browser. ... sudo apt-get install lynx
# BASH function
function spanish() {
if [ "${1}" = "" ] ; then
# usage: spanish [english word]
echo "Usage: spanish dog"
else
lynx -dump -nonumbers -width=160 "http://spanish.dictionary.com/definition/${1}?src=en" | grep "${1} / "
fi
}
@welbornprod
welbornprod / bash weather command
Last active December 11, 2015 23:49
display current weather in your BASH terminal. Uses zip-code to determine current area. Might need to install 'lynx' console browser. ... sudo apt-get install lynx
# BASH function
function weather() {
if [ "${1}" = "" ] ; then
# echo "Usage: weather 90210"
lynx -dump -nonumbers -width=160 "http://weather.unisys.com/forecast.php?Name=90210" | grep -A13 'Latest Observation'
else
lynx -dump -nonumbers -width=160 "http://weather.unisys.com/forecast.php?Name=${1}" | grep -A13 'Latest Observation'
fi
}