This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: gpl-3.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -ex | |
perl -pi -e 's/^#?Port 22$/Port 443/' /etc/ssh/sshd_config | |
service sshd restart || service ssh restart |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import re | |
import sys | |
from subprocess import call | |
if len(sys.argv) > 2: | |
filename, linenum = sys.argv[1], sys.argv[2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Splits a string into parts by a given pattern, interleaving the matched | |
// parts with the unmatched parts. | |
// For example: | |
// splitInterleaved(/a/, "aabbac") => []string{"a", "a", "bb", "a", "c"} | |
// Another way of looking at it is: | |
// regexp.Split() <zip> regexp.FindAllString() <flatten> | |
// | |
func splitInterleaved(re *regexp.Regexp, str string) []string { | |
splits := re.FindAllStringIndex(str, -1) // Find all the split points | |
slice := make([]string, len(splits)*2+1) // Allocate enough space |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# A little wrapper around the Ruby Nokogiri gem for easy markup scanning. | |
# | |
# Usage: cat example.html | noko 'body .header[2]' | |
# Usage: curl -L http://google.com | noko 'table a' | |
# Usage: noko 'css selector' | |
# (Type in some lines, ctrl-d when done.) | |
# | |
require 'nokogiri' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
handler () { | |
kill -s SIGINT $PID | |
while kill -0 $PID &>/dev/null | |
do | |
wait $PID | |
done | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Enumerable | |
# Iterate through a list of things, printing out dots every N items. | |
# | |
# cards.each_with_progress do |card| | |
# ... | |
# end | |
# | |
def each_with_progress(dot_interval = 20) | |
progress = 0 | |
each do |item| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A delayed reaction tooltip handler for jQuery. | |
// Useful for tooltips that are costly to load, such as images. | |
// | |
// $('#article a').delayedHint(function(anchor, callback) { | |
// var imgSrc = $(anchor).attr('href'); | |
// $('<img/>').load(function() { | |
// var frame = $('<span class="frame"></span>').append(this); | |
// callback(frame); | |
// }).attr('src', imgSrc); | |
// }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'thread' | |
# A simple thread pool for running N parallel jobs. | |
# | |
# pool = ThreadPool.new(5) | |
# 20.times do | |
# pool.next_thread{ sleep 2 } | |
# end | |
# pool.join | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A simple logger to STDERR. | |
# | |
# log = SimpleLogger.new | |
# log.info "Helpful log message" | |
# log.debug "Some debugging output" | |
# | |
class SimpleLogger | |
LEVELS = %w(debug info warn error fatal) | |
def initialize(level = :debug) | |
@visible = LEVELS[LEVELS.index(level.to_s)..(-1)] |
NewerOlder