Skip to content

Instantly share code, notes, and snippets.

@metalelf0
metalelf0 / habtm_scope.rb
Created January 28, 2011 13:39
How to define a named scope in a habtm relation
# First model: tag.rb
# note that pomodori is a custom plural for pomodoro
class Tag < ActiveRecord::Base
has_and_belongs_to_many :pomodori
end
# Second model: pomodoro.rb
# here is how to define a Rails 3 scope through the join table:
@battlehorse
battlehorse / index.html
Created November 2, 2011 15:21
Demo script to convert Google Chart Tools charts into PNG images.
<html>
<head>
<script type="text/javascript" src="http://canvg.googlecode.com/svn/trunk/rgbcolor.js"></script>
<script type="text/javascript" src="http://canvg.googlecode.com/svn/trunk/canvg.js"></script>
<script>
function getImgData(chartContainer) {
var chartArea = chartContainer.getElementsByTagName('iframe')[0].
contentDocument.getElementById('chartArea');
var svg = chartArea.innerHTML;
var doc = chartContainer.ownerDocument;
@gavinmh
gavinmh / viterbi.py
Created November 19, 2012 04:27
Viterbi Algorithm
# -*- coding: utf-8 -*-
"""
This is an example of a basic optical character recognition system.
Some components, such as the featurizer, are missing, and have been replaced
with data that I made up.
This system recognizes words produced from an alphabet of 2 letters: 'l' and 'o'.
Words that can be recognized include, 'lol', 'lolol', 'and loooooll'.
We'll assume that this system is used to digitize hand-written notes by Redditors,
or something.
@oste
oste / CommentFormSubscriber.php
Created April 17, 2013 18:58
Steps to modify FOSCommentBundle form and modify it based on thread id
<?php
namespace CommentBundle\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use CommentBundle\Event\CommentFormEvent;
class CommentFormSubscriber implements EventSubscriberInterface
{
public function form(CommentFormEvent $event)
{
@christiangenco
christiangenco / download website assets
Created January 20, 2014 23:23
Use wget to download a website's assets, including images, css, javascript, and html. From http://www.linuxjournal.com/content/downloading-entire-web-site-wget
$ wget \
--recursive \
--no-clobber \
--page-requisites \
--html-extension \
--convert-links \
--domains website.org \
--no-parent \
www.website.org/tutorials/html/
@mlanett
mlanett / rails http status codes
Last active May 14, 2024 08:48
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing
@kevinelliott
kevinelliott / osx-10.10-setup.md
Last active December 1, 2023 08:21
Mac OS X 10.10 Yosemite Setup

Mac OS X 10.10 Yosemite

Custom recipe to get OS X 10.10 Yosemite running from scratch, setup applications and developer environment. I use this gist to keep track of the important software and steps required to have a functioning system after a semi-annual fresh install. On average, I reinstall each computer from scratch every 6 months, and I do not perform upgrades between distros.

This keeps the system performing at top speeds, clean of trojans, spyware, and ensures that I maintain good organizational practices for my content and backups. I highly recommend this.

You are encouraged to fork this and modify it to your heart's content to match your own needs.

Install Software

@PragTob
PragTob / benchmark.rb
Created June 6, 2016 17:49
Ruby flat_map vs. map.flatten
require 'benchmark/ips'
Benchmark.ips do |bm|
list = (0..10_000).to_a
bm.report "flat_map" do
list.flat_map do |x|
[x, x * x]
end
end
Data Structures
- Stacks
- Queues
- Linked lists
- Graphs
- Trees
- Tries
Concepts
- Big O Notation
alias help="tldr"
alias top="sudo htop"
alias yt="youtube-dl"
alias reload="source ~/.zshrc"
alias finder="open -a Finder ./"
alias weather="curl -4 https://wttr.in/Brussels"
alias cat='bat'
alias md='mkdir -p'
alias please=sudo
alias d='dirs -v | head -10'