Skip to content

Instantly share code, notes, and snippets.

Stefan stefanschmidt

Block or report user

Report or block stefanschmidt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@stefanschmidt
stefanschmidt / hash-sha512.sh
Last active Apr 7, 2019
Generate salted SHA-512 hashes
View hash-sha512.sh
# Using mkpasswd and slappasswd we will generate salted SHA-512 hashes
# password: secret
# method 1: using mkpasswd
# requires whois package on Ubuntu
mkpasswd --method=sha-512 --salt=foobar42
$6$foobar42$weYmU8biHjFLegPCuvGBSDaG0QMNucFv4Wq6.TGVK53/U0dp6bTrLYCLAdjecyX5mS1IA8vezYNjzTduU988B0
# method 2: using slappasswd
# requires slapd package on Ubuntu
@stefanschmidt
stefanschmidt / dovecot.sh
Created Mar 24, 2019
Dovecot Command Collection
View dovecot.sh
# reload configuration
doveadm reload
# restart
service dovecot restart
# test authentication
doveadm auth test user@domain.com
# test login with passdb and userdb lookup
@stefanschmidt
stefanschmidt / dns-query.rb
Last active Mar 1, 2019
Perform a DNS query with Ruby
View dns-query.rb
# requires net-dns gem
# query defaults to A record
require 'net/dns'
res = Net::DNS::Resolver.new
packet = res.query("google.com")
packet.answer.first.value
@stefanschmidt
stefanschmidt / mx-query.rb
Created Mar 1, 2019
Perform an MX query with Ruby
View mx-query.rb
# requires net-dns gem
require 'net/dns'
res = Net::DNS::Resolver.new
mx = res.mx("google.com")
mx.first.exchange
@stefanschmidt
stefanschmidt / autenticate-ldap.rb
Last active Mar 1, 2019
Authenticate via LDAP with Ruby
View autenticate-ldap.rb
# Using an LDAP test server we will authenticate the user newton
# http://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/
# requires net-ldap gem
require 'net/ldap'
ldap = Net::LDAP.new
ldap.host = 'ldap.forumsys.com'
ldap.auth "uid=newton,dc=example,dc=com", "password"
if ldap.bind
puts 'authentication succeeded'
@stefanschmidt
stefanschmidt / authenticate-ldap.sh
Last active Apr 7, 2019
Authenticate via LDAP on the command line
View authenticate-ldap.sh
# Using an LDAP test server we will authenticate the user newton
# http://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/
# method 1: using ldapwhoami
# should return "Result: Success (0)" if authentication was successful
ldapwhoami -vvv -h ldap.forumsys.com -D "uid=newton,dc=example,dc=com" -x -w password
# method 2: using ldapsearch
# should return "result: 0 Success" if authentication was successful
ldapsearch -h ldap.forumsys.com -x -D uid=newton,dc=example,dc=com -w password -b "dc=example,dc=com" "(uid=newton)"
@stefanschmidt
stefanschmidt / nrrd-dims.sh
Created Apr 13, 2016
Show dimensions of an NRRD volume on OS X
View nrrd-dims.sh
# depends on teem (available via Homebrew)
unu head volume.nrrd | grep sizes
@stefanschmidt
stefanschmidt / fix-homebrew-owner-perms.sh
Created Apr 12, 2016
Fix ownership and permissions of a multi-user Homebrew installation
View fix-homebrew-owner-perms.sh
# fix owner of files and folders recursively
sudo chown -vR $(whoami) /usr/local /opt/homebrew-cask /Library/Caches/Homebrew
# fix read/write permission of files and folders recursively
chmod -vR ug+rw /usr/local /opt/homebrew-cask /Library/Caches/Homebrew
# fix execute permission of folders recursively
find /usr/local /opt/homebrew-cask /Library/Caches/Homebrew -type d -exec chmod -v ug+x {} +
@stefanschmidt
stefanschmidt / pdftk.rb
Last active Apr 11, 2016
PDFtk Homebrew formula for OS X 10.10 Yosemite
View pdftk.rb
require 'formula'
class PkgExtract < CurlDownloadStrategy
def stage
safe_system '/usr/bin/xar', '-xf', @tarball_path
chdir
safe_system 'mv *.pkg/Payload Payload.gz'
safe_system 'ls | grep -v Payload | xargs rm -r'
end
end
@stefanschmidt
stefanschmidt / switch-guillemets.sh
Last active Mar 13, 2016
Switch orientation of guillemets in Textmate from outwards to inwards (or vice-versa)
View switch-guillemets.sh
# user preferences for the builtin text bundle
PREF_FILE="$HOME/Library/Application Support/Avian/Bundles/Text.tmbundle/Preferences/Miscellaneous.tmPreferences"
# single and double guillemets in both directions
SINGLE_LEFT="<string>‹<\/string>"; SINGLE_RIGHT="<string>›<\/string>"
DOUBLE_LEFT="<string>«<\/string>"; DOUBLE_RIGHT="<string>»<\/string>"
# perl syntax used below
# -i: inplace editing
# -p: iterate over files
You can’t perform that action at this time.