Skip to content

Instantly share code, notes, and snippets.

View skamithi's full-sized avatar

Stanley Karunditu skamithi

  • Raleigh, North Carolina
View GitHub Profile
@skamithi
skamithi / function_defaults.rb
Created June 24, 2013 05:58
create a ruby function with defaults
# Default value for :user_id is generated in this function
def create_project(options = {})
options.reverse_merge!(
:user_id => @user.id
)
FactoryGirl.create(:new_project, options)
end
@skamithi
skamithi / expect4r.gemspec
Created June 28, 2013 15:14
Most basic GemSpec. Call it <name_of_folder>.gemspec
Gem::Specification.new do |s|
s.name = "expect4r"
s.version = '0.1.0'
s.files = Dir["{lib,spec}/**/*", "[A-Z]*", "init.rb"] - ["Gemfile.lock"]
s.require_path = "lib"
s.summary = 'Expect functionality for network equipment'
s.author = ''
end
@skamithi
skamithi / tapaction.coffee
Created July 19, 2013 12:50
notifies user that they tapped on a button.... Work in progress..
# Requires jquery.hammer.js
# Requires wiselinks
# Add class 'tapit' to any clickable element on the page
tapAction = (element) ->
$(element).hammer().on 'tap', ->
$(this).fadeOut {
duration: 200
}
$(this).fadeIn {
@skamithi
skamithi / mount_usershare
Created August 2, 2013 01:33
mount samba share use "net usershare" command. Provide guest access.
net usershare add FLIP /home/backup/myshare "MY SHARE" "Everyone:R" guest_ok=y
# The IP Address Validator accepts the following options
#
# * allow_nil - allows nil values
# * allow_blank - allows blank values
# * allow_cidr - allows /prefixlen CIDR masks in values
#
# the validator will use regular expressions in an attempt to prevent
# malformed IP addresses from being passed to the IPAddr.new initializer
# as this method can be very slow to raise exceptions for malformed input.
class IpAddressValidator < ActiveModel::EachValidator
@skamithi
skamithi / db_cleanout.rake
Last active December 23, 2015 23:19
rake test to clean out test and dev db. Then regenerate both dbs.
namespace :db do
desc 'regenerate test and dev db'
task :regenerate do
Rake::Task['db:drop'].invoke
Rake::Task['db:create'].invoke
Rake::Task['db:migrate'].invoke
Rake::Task['db:test:purge'].invoke
Rake::Task['db:test:prepare'].invoke
end
end
@skamithi
skamithi / gist:6735507
Created September 27, 2013 21:34 — forked from jof/gist:1281122
#!/usr/bin/env ruby
require 'getoptlong'
require 'rubygems'
require 'snmp'
SNMP_COMMUNITY = 'public'
HOSTNAME_BLACKLIST = [ "that_one_switch_thats_down_but_in_dns" ]
ZONE_FILE = /path/to/dns/zone/file
HOSTNAME_REGEX = /^\s?(switch[0-9]+)/i
@skamithi
skamithi / ssh_port_checker.sh
Last active June 23, 2019 16:09
Bash script to detect if SSH port is active on remote host. Used it orchestrating vm creation using ansible.
#!/bin/bash
# Script for checking if SSH port is open
# Only checks that port is open. Not that actually SSH connection can occur
counter=0
result="ssh disabled"
if [ -z "$1" ]
then
echo "hostname argument required. Example ssh_port_checker.sh 10.1.1.1"
@skamithi
skamithi / change_hostname.sh
Last active January 4, 2016 03:19
Change hostname of debian based system without a reboot.
#!/bin/bash
# Change the hostname without reboot
# Applies only to debian based OS
# TODO
# Understand common practises in setting hostnames in /etc/hosts
# in a typical production setting.
@skamithi
skamithi / ansible_tips.yml
Last active August 29, 2015 13:56
Ansible Tips
# Execute gnome action as a user
- name: enable middle click
shell: "sudo -u {{ core_username.stdout }} dbus-launch gsettings set org.gnome.settings-daemon.peripherals.mouse middle-button-enabled true"
# Execute Gem Install using RVM
- name: install knife-solo
shell: >
executable=/bin/bash source /etc/profile.d/rvm.sh;
gem install --no-ri --no-rdoc knife-solo