Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
set -x
log() { echo $*; }
HOSTS="host1 host2"
TODAY=$(date +%Y%m%d)
YESTERDAY=$(date +%Y%m%d -d '1 day ago')
for host in $HOSTS; do
@adam12
adam12 / dragonfly.rb
Last active September 30, 2015 04:13
require 'dragonfly'
# Adding image_optim to Dragonfly
image_optim = ImageOptim.new(nice: 20, threads: 4, verbose: true, advpng: { level: 4 }, jpegoptim: { strip: :all }, jpegrecompress: { quality: 2 }, optipng: { level: 4 }, pngcrush:{ chunks: :alla } )
# Configure
Dragonfly.app.configure do
plugin :imagemagick
# Image optimization processor.
ctrl.createField = function (e) {
e.preventDefault();
ctrl.vm.ContractSectionId = args.contractSection.Id;
var saveField = function () {
return Field.save(ctrl.vm).result
}
saveField()
@adam12
adam12 / context.yml
Last active May 23, 2019 07:37 — forked from thinkerbot/context.yml
ERB vs Erubis vs Erubi
list:
- name: Adobe Systems
name2: Adobe Systems Inc.
url: http://www.adobe.com
symbol: ADBE
price: 39.26
change: 0.13
ratio: 0.33
- name: Advanced Micro Devices
name2: Advanced Micro Devices Inc.
@adam12
adam12 / kinda?.rb
Last active January 20, 2017 03:36 — forked from mfifth/full error
require 'sunspot'
require 'sunspot/rails'
require 'feedjira/feed'
module Sunspot
module Feedjira::Feed
def self.included(base)
base.class_eval do
extend Sunspot::Rails::Searchable::ActsAsMethods
Sunspot::Adapters::DataAccessor.register(DataAccessor, base)
@adam12
adam12 / ipset-geoblock.sh
Last active December 10, 2019 20:47
Block some countries from SSH-bruteforcing using ipset
#!/bin/sh
# vim:ts=2:sts=2:sw=2:et:ft=sh:
IPSET="ipset"
IPTABLES="iptables"
SETNAME="geoblock"
$IPSET create $SETNAME hash:net
for IP in $(curl -s http://www.ipdeny.com/ipblocks/data/countries/{cn,ru,kr,pk,tw,sg,hk,ar}.zone)
do
$IPSET add $SETNAME $IP
@adam12
adam12 / add-user.sh
Last active February 26, 2017 03:18
Add a user to an openSUSE system with a btrfs filesystem it can manage via snapper
#!/bin/sh
# vim:ts=2:sts=2:sw=2:et:ft=sh:
user=$1
home="/home/$user"
[ -z "$user" ] && echo "missing user" && exit 1
btrfs subvolume create $home > /dev/null
chattr +c $home
@adam12
adam12 / backup-vm.sh
Created March 28, 2017 19:02 — forked from twilligon/README.md
back up a full image of a libvirt-based VM while it's running
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
DOMAIN="$1"
UUID=$(sudo virsh dumpxml $DOMAIN | grep uuid | cut -d">" -f2 | cut -d"<" -f1)
DISK_LOCATION=$(sudo virsh domblklist "$DOMAIN" | grep sda | tr -s " " | cut -d" " -f2-)
# Export Borg encryption key
export BORG_PASSPHRASE="<your key>"
@adam12
adam12 / Gemfile
Last active June 13, 2017 02:17 — forked from tatey/benchmark.rb
Mocha VS MiniTest::Mock and SimpleDelegate VS SimpleMock VS RR
# frozen_string_literal: true
source "https://rubygems.org"
gem "benchmark-ips"
gem "rr"
gem "mocha"
gem "simple_mock"
@adam12
adam12 / ip-counter.sh
Last active July 27, 2017 02:44
Provided list of netblocks on STDIN, count total # of IPs
ruby -ne 'BEGIN{$n=0}; ~/\/(\d+)/ && $n += (2 ** (32 - $1.to_i)); END{puts $n}'