Skip to content

Instantly share code, notes, and snippets.

@ktaragorn
ktaragorn / puma.sh
Last active January 15, 2018 09:08 — forked from ivanxuu/puma.sh
#! /bin/sh
### BEGIN INIT INFO
# Provides: pumacontrol
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Puma web server
@ktaragorn
ktaragorn / datalist_input.rb
Last active August 29, 2015 14:03
Formtastic input for HTML5 datalist
# implementing http://www.w3schools.com/tags/tag_datalist.asp
class DatalistInput
include Formtastic::Inputs::Base
include Formtastic::Inputs::Base::Stringish
include Formtastic::Inputs::Base::Collections
def to_html
@name = input_html_options[:id].gsub("_id", "")
input_wrapping do
label_html <<
@ktaragorn
ktaragorn / git_move_file_history.rb
Last active August 29, 2015 14:07
Rewrite history to move files from the root of the project into sub dir
files = Dir.entries(".")
sub_dir = "clowns_as_many"
(files - [".", "..", ".git", ".gitignore", "lib", ".DS_Store", "move.rb"]).each do |file|
cmd = "git filter-branch -f --tree-filter \'if [ -e #{file} ]; then mkdir -p #{sub_dir} && mv #{file} #{sub_dir}/; fi\' HEAD"
p cmd
system cmd
end
@ktaragorn
ktaragorn / loopback-audio
Created February 5, 2015 14:23
Script that enabled loopback mode via pulseaudio and disabled it after use. This was used to loop audio from my laptop through my desktop to my monitor
#!/bin/sh
num=$(pactl load-module module-loopback channels=2)
echo $num
pactl set-source-port alsa_input.pci-0000_00_1e.2.analog-stereo analog-input-linein
pactl set-source-volume alsa_input.pci-0000_00_1e.2.analog-stereo 45%
zenity --info --title="Line In Active" --text="Press ok after Game Session"
pactl set-source-port alsa_input.pci-0000_00_1e.2.analog-stereo analog-input-microphone\;input-microphone-1
pactl set-source-volume alsa_input.pci-0000_00_1e.2.analog-stereo 100%
@ktaragorn
ktaragorn / apt-mirrors.sh
Created September 2, 2015 02:44
Replace ubuntu sources with mirrors:// sources - make apt faster
#http://askubuntu.com/a/9035/92812
sudo sed -i 's/http\:\/\/security.ubuntu.com\/ubuntu/mirror\:\/\/mirrors.ubuntu.com\/mirrors.txt/' /etc/apt/sources.list
sudo sed -i 's/http\:\/\/extras.ubuntu.com\/ubuntu/mirror\:\/\/mirrors.ubuntu.com\/mirrors.txt/' /etc/apt/sources.list
sudo sed -i 's/http\:\/\/archive.ubuntu.com\/ubuntu/mirror\:\/\/mirrors.ubuntu.com\/mirrors.txt/' /etc/apt/sources.list
[defaults]
#this should be hostfile if ur ansible version < 1.9
#this means you dont have to manually specify it in command line
inventory = inventory.ini
[ssh_connection]
ssh_args = -o ForwardAgent=yes
#http://www.ansible.com/blog/2014/01/15/ssh-connection-upgrades-coming-in-ansible-1-5
pipelining=True
@ktaragorn
ktaragorn / deploy.yml
Created September 30, 2015 09:38
Ansible playbook to deploy by git and restart service, service specified by upstart
---
- name: Deploy Code
hosts: all
tasks:
- name: Deploy latest code from git
git:
repo: <<repo>>
dest: <<dest>>
accept_hostkey: true
version: master
@ktaragorn
ktaragorn / tasks.py
Created October 23, 2015 16:18
Invoke tasks.py file to cover basic tasks - install packages and test/automated tests
from invoke import run, task
from invoke.exceptions import Failure
@task
def test():
run("python -m unittest discover test")
@task
def freeze():
run("pip freeze > requirements.txt")
@ktaragorn
ktaragorn / config.py
Created October 26, 2015 08:08
A nice way to keep app config in yaml format and load it into a attr accessible object
import yaml
from awesome_print.awesome_print import format as frmt
class AttrDict(object):
def __init__(self, dct):
self.dict = dct
def __repr__(self):
return repr(self.dict)
def __str__(self):
@ktaragorn
ktaragorn / Vagrantfile
Created October 30, 2015 03:58
Vagrant provisioning configure with shell and ansible
# this is apt-mirrors.sh to make all apt sources pick the closest mirrors.
# this works very well and inline does not, perhaps more escaping needed
config.vm.provision "shell", path: "https://gist.githubusercontent.com/ktaragorn/81496cb4f8ff4bfddb00/raw/50b2d5530ef39aab958d067c00404de6f212c254/apt-mirrors.sh"
config.vm.provision "ansible" do |ansible|
ansible.playbook = "ansible/setup.yml"
ansible.groups = { "vagrant" => "all"}
end