Skip to content

Instantly share code, notes, and snippets.

@sharipov-ru
sharipov-ru / development.rb
Last active December 20, 2016 14:20 — forked from dhh/gist:2492118
config.middleware.use RoutesReloader
def back_or_home_path
referrer = controller.respond_to?(:request) && controller.request.env['HTTP_REFERER']
local_referrer = referrer && URI.parse(referrer).host == controller.request.host
if referrer && local_referrer
referrer
else
root_path
end
end
@krisleech
krisleech / 00-helper.rb
Created January 17, 2014 18:13
view conditional with yield
class MyPresenter
def initialize(user)
@user = user
end
def admin_only(&block)
yield if user.admin?
end
end
@demirhanaydin
demirhanaydin / tire-parent-child-example.rb
Last active December 22, 2015 23:48
Elasticsearch parent/child example with tire
require 'rubygems'
require 'tire'
Tire.configure { logger 'elasticsearch.log', :level => 'debug' }
class Document
attr_accessor :title, :content
include Tire::Model::Persistence
include Tire::Model::Search
include Tire::Model::Callbacks
MyExceptions = [RangeError, RegexpError, IOError].freeze
begin
raise IOError, "should be rescued"
rescue *MyExceptions => e
puts e
end
@somebody32
somebody32 / gist:5232120
Last active October 4, 2022 08:19
Список литературы для ознакомления с concurrent programming и реализацией этих принципов и подходов на ruby. Огромное спасибо @brainopia за составление.

Введение

Начать стоит отсюда. Не пугайтесь то, что это книга по незнакомой OS, эти термины практически везде одинаковые и здесь они изложены в понятной для начинающих форме.

http://www.qnx.com/developers/docs/6.4.1/neutrino/getting_started/s1_procs.html

Прочесть нужно треть главы до подраздела "Starting a process", если С не пугает, читайте полностью. После прочтения вы будете понимать, что такое process, thread, mutex, priorites, semaphores, scheduler, contex-switch, kernel states.

Ruby

@nlevchuk
nlevchuk / deploy.rb
Created November 29, 2012 09:02
config/deploy.rb
require 'bundler/capistrano'
require "rvm/capistrano"
require 'capistrano/ext/multistage'
load 'deploy/assets'
set :rvm_path, '/home/<USERNAME>/.rvm'
set :rvm_bin_path, '/home/<USERNAME>/.rvm/bin'
set :repository, '[email protected]:<GIT_USERNAME>/<REPOSITORY_NAME>.git'
set :scm, :git
tell application "iTerm"
activate
tell (make new terminal)
tell (launch session "initial_session") to write text "cd ~/workspace/project1; clear"
tell i term application "System Events" to keystroke "D" using command down
tell last item of sessions to write text "cd ~/workspace/work/project2; clear"
tell i term application "System Events" to keystroke "d" using command down
tell last item of sessions to write text "cd ~/workspace/work/project3; clear"
@yoshiori
yoshiori / coderwall.html
Created July 12, 2012 07:54
octopress coderwall badges
{% if site.coderwall_user %}
<section class="well">
<ul class="nav">
<li class="nav-header">Coderwall Badges</li>
</ul>
<div id="coderwall_badges"></div>
<a href="http://coderwall.com/{{site.coderwall_user}}">@{{site.coderwall_user}}</a> on coderwall
<script type="text/javascript">
$(document).ready(function(){
$.getJSON("http://coderwall.com/{{site.coderwall_user}}.json?callback=?", function(data){
@tobyhede
tobyhede / postsql.sql
Created May 17, 2012 03:08
PostgreSQL as JSON Document Store
-- PostgreSQL 9.2 beta (for the new JSON datatype)
-- You can actually use an earlier version and a TEXT type too
-- PL/V8 http://code.google.com/p/plv8js/wiki/PLV8
-- Inspired by
-- http://people.planetpostgresql.org/andrew/index.php?/archives/249-Using-PLV8-to-index-JSON.html
-- http://ssql-pgaustin.herokuapp.com/#1
-- JSON Types need to be mapped into corresponding PG types
--