Skip to content

Instantly share code, notes, and snippets.

View mrcasals's full-sized avatar
👨‍🚀
🚀

Marc Riera mrcasals

👨‍🚀
🚀
View GitHub Profile
require 'nokogiri'
class Html2Md
class Link < Struct.new(:href, :title)
end
class Format < Struct.new(:name, :head, :body, :opened)
end
WIDTH = 80

An ActiveRecord conundrum

I'm going to describe a weird problem I faced when using ActiveRecord today. To protect the innocent, I'm not going to talk about the app I'm actually working on but will instead discuss a hypothetical but isomorphic database design for a clone of the popular blogging platform Tumblr.

Tumblr lets you publish various different sorts of content. We might be tempted to shove all these types in a big STI table, but the types are all quite different from one another and so we give them their own tables.

@chriseidhof
chriseidhof / pechakucha.sh
Last active January 19, 2017 11:56
Advance Deckset slides every 20 seconds
#/bin/bash
# Works from Deckset 1.2 upwards. Make sure you have a document opened.
#
# If you're using the Trial version change "Deckset" to "Deckset Trial"
osascript -e 'repeat' -e 'tell application "Deckset" to tell document 1 to set slideIndex to slideIndex + 1' -e 'delay 20' -e 'end repeat'
#!/bin/zsh
# usage: wake_me <command>
echo $@
$@
notification='display notification "'$@'" with title "Finished"'
osascript -e "$notification"
say -v Deranged "it's finally, finally finished. at last."
@otobrglez
otobrglez / jaccard_recommendation.rb
Last active April 2, 2024 17:51
Simple recommendation system written in Ruby based on Jaccard index.
# Simple Recommendation Engine in Ruby
# Visit: http://otobrglez.opalab.com
# Author: Oto Brglez <otobrglez@gmail.com>
class Book < Struct.new(:title)
def words
@words ||= self.title.gsub(/[a-zA-Z]{3,}/).map(&:downcase).uniq.sort
end
@wbroek
wbroek / genymotionwithplay.txt
Last active February 12, 2024 03:22
Genymotion with Google Play Services for ARM
NOTE: Easier way is the X86 way, described on https://www.genymotion.com/help/desktop/faq/#google-play-services
Download the following ZIPs:
ARM Translation Installer v1.1 (http://www.mirrorcreator.com/files/0ZIO8PME/Genymotion-ARM-Translation_v1.1.zip_links)
Download the correct GApps for your Android version:
Google Apps for Android 6.0 (https://www.androidfilehost.com/?fid=24052804347835438 - benzo-gapps-M-20151011-signed-chroma-r3.zip)
Google Apps for Android 5.1 (https://www.androidfilehost.com/?fid=96042739161891406 - gapps-L-4-21-15.zip)
Google Apps for Android 5.0 (https://www.androidfilehost.com/?fid=95784891001614559 - gapps-lp-20141109-signed.zip)
@sztupy
sztupy / INSTALL.md
Last active April 4, 2018 07:49 — forked from namuol/INSTALL.md

rage-quit plugin for oh-my-zsh

based on rage-quit support for bash

HOW TO INSTALL

Put the files below inside ~/.oh-my-zsh/custom/plugins/fuck

Also chmod a+x the flip command.

@bitemyapp
bitemyapp / gist:8739525
Last active May 7, 2021 23:22
Learning Haskell
@peterc
peterc / methods_returning.rb
Last active October 29, 2023 03:10
Object#methods_returning - to work out which method on an object returns what we want
require 'stringio'
require 'timeout'
class Object
def methods_returning(expected, *args, &blk)
old_stdout = $>
$> = StringIO.new
methods.select do |meth|
Timeout::timeout(1) { dup.public_send(meth, *args, &blk) == expected rescue false } rescue false
@txus
txus / .pryrc.rb
Last active December 18, 2015 17:59
Pry command to trace a method invocation and log backtraces of each invocation to a file.
def write_backtrace name, backtrace, filename
exceptions = Regexp.union([
/\.bundle/,
/spec/,
/test/,
/lib\/ruby\/1.9.1/
])
backtrace.reject! { |line| line =~ exceptions }