Skip to content

Instantly share code, notes, and snippets.

View prandelicious's full-sized avatar
🏠
Working from home

Francis prandelicious

🏠
Working from home
View GitHub Profile
git checkout -b my-custom
git add .
git commit -m "fix mackup"
git checkout master
upgrade_oh_my_zsh
git merge my-custom
@prandelicious
prandelicious / rename.sh
Created March 23, 2018 14:17
Rename a bunch of files
rename -n 's/^[0-9]+ - //' *
@prandelicious
prandelicious / main.yml
Created March 23, 2018 13:27
[Ansible] Write output of several hosts into a single list/display
- hosts: mygroup
gather_facts: false
tasks:
- shell: date
register: date_res
changed_when: false
- debug:
msg: "{{ ansible_play_hosts | map('extract', hostvars, 'date_res') | map(attribute='stdout') | list }}"
run_once: yes
@prandelicious
prandelicious / .profile
Created March 23, 2018 02:53
Make tmux your default shell
if [[ -z "$TMUX" ]]; then
if tmux has-session 2>/dev/null; then
exec tmux attach
else
exec tmux
fi
fi
@prandelicious
prandelicious / main.yml
Created March 22, 2018 09:37
[Ansible] Aggregate results from multiple hosts into a single var for later use
---
- hosts: all
vars:
uuids: |
{%- set o=[] %}
{%- for i in play_hosts %}
{%- if o.append(hostvars[i].uuid) %}
{%- endif %}
{%- endfor %}
{{ o }}
@prandelicious
prandelicious / main.yml
Last active March 22, 2018 09:38
[Ansible] Run playbook on the local machine
ansible-playbook -i 'localhost,' plays/get_all_cronjobs.yml --connection=local --ask-become-pass
@prandelicious
prandelicious / main.yml
Last active March 22, 2018 09:38
[Ansible] Ways to write output of a register variable to a local file
- name: Write to local disk
local_action: "copy content='{{ result.stdout_lines }}' dest='../files/list_cronjobs/list_cronjobs.txt'"
- name: Write to local disk
lineinfile: dest=../files/list_cronjobs/list_cronjobs.txt create=yes line="{{ result.stdout_lines }}"
delegate_to: 127.0.0.1
@prandelicious
prandelicious / dict_subclass.py
Created August 26, 2017 04:58
Sub-classing dict for better readability
class objdict(dict):
def __getattr__(self, name):
if name in self:
return self[name]
else:
raise AttributeError("No such attribute: " + name)
def __setattr__(self, name, value):
self[name] = value
@prandelicious
prandelicious / python.json
Created August 25, 2017 08:33
[VS Code snippet] Docstring template for functions
"Function Docstring": {
"prefix": "docf",
"body": [
"\"\"\"${1:Short description of what function does}.",
"${2:Long description here}.\n",
"Args:",
"\t${3:arg1} (${4:type}): ${5:Description of $3}\n",
"Returns:",
"\t${6:type}: ${7:Description of return value}",
"\"\"\"",
@prandelicious
prandelicious / python.json
Last active June 13, 2023 04:21
[VS Code snippet] Create default python header content
"Default Header": {
"prefix": "header",
"body": [
"#!/usr/bin/env python",
"# -*- coding: utf-8 -*-",
"\"\"\"${1:Custom module name or brief description}.\n",
"${2:Enter description of this module}",
"",
"__author__ = ${3:[authors]}",
"__copyright__ = Copyright 2018",