Skip to content

Instantly share code, notes, and snippets.

@SimplGy
SimplGy / renameToHash.sh
Last active July 27, 2023 07:30
Rename files with a hash based on their contents. eg: `abc.jpg` to `3101ace8db9f.jpg`. Useful for detecting duplicates.
#!/bin/bash
# TODO: skip tiny files (so small they couldn't be photos)
# TODO: make sure sym links and other file system oddities are handled
# TODO: look at paralellization for perf boost
#
# Constants
#
CHAR_COUNT=12
BLOCK_COUNT=6
-- strip_md(text) - strips markdown from text
-- (c) 2014 Felix Buenemann https://github.com/felixbuenemann
-- License: Public Domain
CREATE OR REPLACE FUNCTION strip_md(input text) RETURNS text AS $$
BEGIN
-- strip html tags
input := regexp_replace(input, '<[^>]+>', '', 'g');
-- strip list leaders and blockquotes
input := regexp_replace(input, '^([\s]*)([\*\-\+]|\d\.|>)\s+', '\1', 'ng');
-- strip setext header underlines
@markbates
markbates / gist:4240848
Created December 8, 2012 16:06
Getting Started with Rack

If you're writing web applications with Ruby there comes a time when you might need something a lot simpler, or even faster, than Ruby on Rails or the Sinatra micro-framework. Enter Rack.

Rack describes itself as follows:

Rack provides a minimal interface between webservers supporting Ruby and Ruby frameworks.

Before Rack came along Ruby web frameworks all implemented their own interfaces, which made it incredibly difficult to write web servers for them, or to share code between two different frameworks. Now almost all Ruby web frameworks implement Rack, including Rails and Sinatra, meaning that these applications can now behave in a similar fashion to one another.

At it's core Rack provides a great set of tools to allow you to build the most simple web application or interface you can. Rack applications can be written in a single line of code. But we're getting ahead of ourselves a bit.