Skip to content

Instantly share code, notes, and snippets.

View denispeplin's full-sized avatar

Denis denispeplin

View GitHub Profile
@torsten
torsten / proxy.rb
Last active April 30, 2024 17:53
A quick HTTP proxy server in Ruby.
#!/usr/bin/env ruby
# A quick and dirty implementation of an HTTP proxy server in Ruby
# because I did not want to install anything.
#
# Copyright (C) 2009-2014 Torsten Becker <torsten.becker@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
@matenia
matenia / page.rb
Created February 25, 2012 14:35
Route Constraints, mapping Friendly Id 4.x to /:id of any model
# app/models/page.rb
class Page < ActiveRecord::Base
extend FriendlyId
friendly_id :title, :use => [:slugged, :history]
end
@nextroy
nextroy / custom.js
Created June 27, 2012 12:42 — forked from drewjoh/custom.js
Dynamic (AJAX) loaded Bootstrap Modal (Bootstrap 2.0) : Fix for removing the response Modal content
$(document).ready(function() {
// Support for AJAX loaded modal window.
// Focuses on first input textbox after it loads the window.
$('[data-toggle="modal"]').bind('click',function(e) {
e.preventDefault();
var url = $(this).attr('href');
if (url.indexOf('#') == 0) {
$('#response_modal').modal('open');
} else {
@peter
peter / creating-edgerails-app.sh
Created June 30, 2012 21:03
Creating and Deploying an EdgeRails (Rails 4) Application to Heroku
# 0. Make sure you have Ruby 1.9.3 installed, and optionally RVM and PostgreSQL
# 0.2 If you are on the Mac, make sure you have a c compiler by installing XCode Command Line Tools or gcc4.2 with homebrew
# https://github.com/mxcl/homebrew/wiki/Custom-GCC-and-cross-compilers
# 0.5 Make sure you have bundler version ~> 1.2 as Rails depends on it
gem install bundler
# 1. Get edge Rails source (master branch)
git clone https://github.com/rails/rails.git
@denispeplin
denispeplin / simple_form_display_filter.rb
Created November 1, 2012 06:25
Add display_filter option to simple_form
module SimpleForm
class FormBuilder < ActionView::Helpers::FormBuilder
# tried to monkey patch without copy'n'pasting, broke associations
def input(attribute_name, options={}, &block)
options = @defaults.deep_dup.deep_merge(options) if @defaults
chosen =
if name = options[:wrapper]
name.respond_to?(:render) ? name : SimpleForm.wrapper(name)
else
@julian7
julian7 / include-vs-cover-vs-between.rb
Created November 11, 2012 18:09
include? vs. cover? vs. between?
require 'date'
require 'benchmark'
n = 1_000_000
start_date = Date.new(2012, 01, 01)
end_date = Date.new(2012, 03, 01)
act_date = Date.new(2012, 02, 01)
Benchmark.bm(10) do |x|
x.report('include?') do
@coldnebo
coldnebo / rails_trace.rb
Last active December 1, 2018 08:10
This Rack middleware for Rails3 lets you see a call-trace of the lines of ruby code in your application invoked during a single request. Only code within your app is considered (i.e. in the /app folder). This expands on my previous attempt (https://gist.github.com/3077744). Example of output in comments below.
require 'singleton'
# outputs a colored call-trace graph to the Rails logger of the lines of ruby code
# invoked during a single request.
#
# Example:
#
# 1) Make sure this file is loaded in an initializer
#
# 2) Add the following to your application.rb in Rails3:
@dypsilon
dypsilon / frontendDevlopmentBookmarks.md
Last active May 7, 2024 01:27
A badass list of frontend development resources I collected over time.
@henrik
henrik / chain.exs
Last active December 4, 2020 05:41
Silly #elixir-lang macro experiment for Ruby-like method chaining. Don't use this for serious purposes :)
defmodule Chain do
defmacro chain(ex) do
parse(ex)
end
defp parse({:., _, [first_arg, function_name]}, more_args) do
args = [first_arg|more_args] |> Enum.map(&parse/1)
apply(String, function_name, args)
end
@maglietti
maglietti / gistColaboration.md
Created August 21, 2015 16:33
How to collaborate on a gist

To colaborate on a gist:

  1. Clone your gist repo locally
  2. Add your friend’s fork as a remote e.g. if your friend is named Cindy: git remote add-url cindy https://gist.github.com/cindy/df03bdacaef75a80f310
  3. Fetch your friend’s commits: git fetch cindy/master
  4. Merge your friend’s changes into your repo: git merge cindy/master
  5. Push the changes back to GitHub: git push origin/master