Skip to content

Instantly share code, notes, and snippets.

View manuelmeurer's full-sized avatar
🤷‍♂️

Manuel Meurer manuelmeurer

🤷‍♂️
View GitHub Profile
module AllCacheKey
extend ActiveSupport::Concern
module ClassMethods
def cache_key
pluck("COUNT(*)", "MAX(updated_at)").flatten.map(&:to_i).join("-")
end
end
end
@epicserve
epicserve / redis_key_sizes.sh
Last active February 21, 2024 18:30
A simple script to print the size of all your Redis keys.
#!/usr/bin/env bash
# This script prints out all of your Redis keys and their size in a human readable format
# Copyright 2013 Brent O'Connor
# License: http://www.apache.org/licenses/LICENSE-2.0
human_size() {
awk -v sum="$1" ' BEGIN {hum[1024^3]="Gb"; hum[1024^2]="Mb"; hum[1024]="Kb"; for (x=1024^3; x>=1024; x/=1024) { if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; } } if (sum<1024) print "1kb"; } '
}
@louismullie
louismullie / textrank-sentence.rb
Last active September 13, 2022 07:02
An implementation of the TextRank algorithm for extractive summarization using Treat + GraphRank. Uses the number of non-stop-words with a common stem as a similarity metric between sentences.
require 'graph-rank'
require 'treat'
# Implements the PageRank algorithm for
# unsupervised extractive summarization.
#
# Reference: R. Mihalcea and P. Tarau, “TextRank:
# Bringing Order into Texts,” in Proceedings of
# EMNLP 2004. Association for Computational
# Linguistics, 2004, pp. 404–411.
@pauldatta
pauldatta / rabl_grape.rb
Created December 31, 2012 13:00
Using Rabl with Grape Trying to get view helpers to work within Rabl templates that are called from Grape. @pauldatta
# https://github.com/drapergem/draper/wiki/Using-Rails-Path-Helpers-in-Draper-Decorators-with-Grape
# https://github.com/nesquena/rabl/wiki/Using-Rabl-with-Grape
module Grape
class Endpoint
include Rails.application.routes.url_helpers
default_url_options[:host] = ::Rails.application.routes.default_url_options[:host]
end
end
@psychocandy
psychocandy / URI-monkey-patch.rb
Created July 17, 2012 16:11
Fix ArgumentError invalid %-encoding for malformed URLs
# The following should prevent an ArgumentError "invalid %-encoding (...%)" exception from being raised for malformed URLs.
# To use this code simply drop this in your rails app initializers.
# See: https://github.com/rack/rack/issues/337
# Taken from: http://stackoverflow.com/a/11162317/1075006
module URI
major, minor, patch = RUBY_VERSION.split('.').map { |v| v.to_i }
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@pgib
pgib / haml_renamer.sh
Created October 26, 2011 20:16
Rename all .haml to .html.haml
#!/bin/sh
for h in `find . -name '*.haml'`; do
if ! echo $h | grep -q ".html.haml"; then
hh=`echo $h | sed -e s/.haml/.html.haml/`
if [ -e $hh ]; then
echo "Can't rename $h to $hh because $hh already exists. :("
else
@butlermh
butlermh / wishlist.rb
Created June 16, 2011 19:29
Find out what books are available on your Amazon wishlist on Kindle
#!/usr/bin/ruby
require 'rubygems'
require 'open-uri'
require 'nokogiri'
require 'net/http'
require 'uri'
require 'amazon/aws/search'
include Amazon::AWS
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')