Skip to content

Instantly share code, notes, and snippets.

@senorsmile
senorsmile / php_limitlessled_example.php
Created January 3, 2014 01:12
php example to control limitlessled light bulb
<?php
## This assumes proper privileges by php to write to /dev/udp/*
ipaddress="192.168.0.201";
portnum="50000";
allon="\x35\00\x55";
shell_exec(echo -n -e "$allon" > /dev/udp/"$ipaddress"/"$portnum");
?>
#!/usr/bin/env bash
playbook="./site.yml"
hostsfile="./hosts"
## cd to directory of playbook
cd ${0%/*}
time ansible-playbook "$playbook" -i "${hostsfile}" "$@"
@senorsmile
senorsmile / filters.py
Last active September 17, 2015 20:04 — forked from viesti/filters.py
Ansible filter plugin to create rules fo ec2_group
def make_rules(hosts, ports, proto):
return [{"proto": proto,
"from_port": port,
"to_port": port,
"cidr_ip": host} for host in hosts for port in map(int, ports.split(","))]
class FilterModule(object):
def filters(self):
return {'make_rules': make_rules}
#!/usr/bin/env bash
perl_version='5.25.6'
perl_version='5.24.0'
verify_pkg() {
pkg="$1"
[[ $(which "${pkg}") ]] || {
echo "${pkg} not found. Exiting..."
exit 1
@senorsmile
senorsmile / array_slice.bash
Created December 14, 2016 06:28
array slicing in bash
#!/usr/bin/env bash
array=(zero one two three four five)
echo "${array[@]:1:3}"
## one two three
echo "${array[@]:3}"
## three four five
@senorsmile
senorsmile / custom_type.py
Created December 28, 2016 04:27
simplified custom type in python
#!/usr/bin/env python
class MyType(object):
def __init__(self, value):
self.value = value
def __add__(self, other): #overload '+'
if not isinstance(other, MyType): #only works on MyType types
return NotImplemented
return self.__class__(self.value + other.value)
@senorsmile
senorsmile / rsync_backup_template.sh
Last active January 15, 2017 20:32
add message if rsync already running
#!/usr/bin/env bash
#--------
# ALL dirs must end with a backslash
#--------
now=$(date +%Y-%m-%d_%H:%M:%S_%N)
src='/home/shaun/'
dest_url='127.0.0.1'
dest_dir='/home/shaun/rsync_backups/'
---
##- Do this
- name: Install foo package
apt:
name: foo
state: present
##- not this
- name: Install foo package
apt: name=foo state=present
---
all:
vars:
k8s_pods:
- name: kuard-5-6
#state: absent
volumes:
- name: "kuard-data"
volume_type: 'nfs'
server: "{{ hostvars['k8s-slave1']['ansible_eth1']['ipv4']['address'] }}"
@senorsmile
senorsmile / gist:1bf4b68820460f612a2da8c345237f3b
Created October 17, 2020 13:59
vim - convert ansible one line tasks to multiline yaml
:%s/\([a-z0-9_]\+\)=\(\({{ \)\=[a-z0-9._]\+\( }}\)\=\)/\r \1: "\2"/g