This file contains 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 python | |
from operator import itemgetter | |
import sys | |
import json | |
import math | |
import re | |
# usage: ./color.py [hex RGB color] | |
# returns the five 'closest' CSS color names to the input color |
This file contains 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
unique_name() { | |
local base=$1 | |
local ext=$2 | |
local name="${base}.${ext}" | |
if [[ -e $name || -L $name ]]; then | |
i=1 | |
while [[ -e "${base}-${i}.${ext}" || -L "${base}-${i}.${ext}" ]]; do | |
let i++ | |
done | |
name="${base}-${i}.${ext}" |
This file contains 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
class BackupFileWriter: | |
def __init__(self, path, mode='w', prefix='buf-temp-'): | |
self.path = path | |
self.mode = mode | |
self.prefix = prefix | |
self.prev = f"{path}.prev" | |
self.temp = None | |
self.handle = None | |
def __enter__(self): |
This file contains 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 | |
require 'yaml' | |
require 'fileutils' | |
# this utility checks staged files and compares them against | |
# the files listed in `.rubocop_todo.yml` that have 'pending' | |
# rubocop violations to be fixed. It produces a report | |
# that shows whether any of those staged files requires | |
# attention |
This file contains 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
import com.ibm.icu.text.CharsetDetector; | |
import com.ibm.icu.text.CharsetMatch; | |
import java.io.BufferedInputStream; | |
import java.io.FileInputStream; | |
import java.io.IOException; | |
public class Detector { | |
public static void main(String[] args) { |
This file contains 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 python | |
# Merges items spread over multiple MARC XML records | |
# into a single record. Some ILSes will not export MARC21 | |
# that is "too large", and will output the same bibliographic record | |
# multiple times. | |
# usage: first, convert your marc21 to MARCXML (see marcrenaissance.sh gist) | |
# ensure that all records with the same control number come out in a 'clump', | |
# e.g. by sorting on control number |
This file contains 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
package main | |
import ( | |
"fmt" | |
"io" | |
"bytes" | |
"os" | |
"log" | |
"encoding/xml" | |
) |
This file contains 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 python3 | |
import os | |
import shutil | |
class Backer: | |
"""Implements a backup strategy for a file. You might | |
use this when preparing to overwrite an important configuration | |
or log file that's not under version control.""" |
This file contains 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
# refinement for Hash class that allows declarative remapping functions | |
# | |
# #remap(mapping) | |
# and | |
# #remap!(mapping) | |
# methods. | |
# The `mapping` hash maps key names in the original hash to their | |
# names in the resulting hash, e.g. | |
# `{ foo: 'bar' }.remap({foo: :fu}) => `{ fu: 'bar' }` | |
# There are two special values that can be used in a mapping: |
This file contains 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 | |
# Makes a class globally configurable, e.g. in a Rails initializer. | |
# Usage: | |
# `class MyClass | |
# include Configurable | |
# create_config do | |
# # url attribute has a default value, which is the return value of the block | |
# url { 'http://www.example.com'} | |
# # name attribute is allowed but has no default value |
NewerOlder