Skip to content

Instantly share code, notes, and snippets.

@shock
shock / heredoc.rb
Created July 21, 2016 15:16
String object extensions for handling proper indentation duration HEREDOC interpolation of multi-line strings.
# Created in response to Stack Overflow question:
# http://stackoverflow.com/questions/38504004/interpolate-multiline-string-with-correct-indent
module CoreExtensions
module String
module Heredoc
# Special character to flag lines that are part of a multiline HEREDOC interpolation
# Any character that is not part of the output string will work. Using "\r" because
# it's rarely used in hard-coded strings.
@allaire
allaire / upload_erb.rb
Last active March 28, 2018 21:53
Capistrano 3 upload file from erb template
def template(from, to, options = {})
template_path = File.expand_path("../../templates/#{from}", __FILE__)
template = ERB.new(File.new(template_path).read).result(binding)
upload! StringIO.new(template), to, mode: 0644 # Otherwise it's set to 0640, which is not readable by other users (https://github.com/net-ssh/net-scp/blob/master/lib/net/scp/upload.rb#L63)
sudo "chown root:root #{to}" if options[:as_root]
end
@vladshub
vladshub / nc_api.sh
Last active July 31, 2018 20:14
nginx auth_request doesn't post :(
#!/bin/bash
while true ; do echo -e "HTTP/1.1 200 OK\n\n $(date)" | nc -l -p 1501 ; done
@wejrowski
wejrowski / block-to-partial
Created August 17, 2011 22:10
Passing Blocks to Rails partials
<%
#
# I originally needed to create a sidebar partial that had a div area where I could place custom links into. Finally found it.
# When I was trying to figure this out before and realized I needed to pass the view into :layout, rather than just using render 'layout'. Not sure why the block can't be passed otherwise but nonetheless...
#
# For explanation of options see
# http://guides.rubyonrails.org/layouts_and_rendering.html#options-for-render
#
%>
@ohryan
ohryan / responsive-align.less
Last active April 30, 2019 17:27
Bootstrap 3 Responsive Text Align
.text-xs-left { text-align: left; }
.text-xs-right { text-align: right; }
.text-xs-center { text-align: center; }
.text-xs-justify { text-align: justify; }
@media (min-width: @screen-sm-min) {
.text-sm-left { text-align: left; }
.text-sm-right { text-align: right; }
.text-sm-center { text-align: center; }
.text-sm-justify { text-align: justify; }
@scottwillson
scottwillson / Tsung Rails authenticity_token
Created January 30, 2013 21:07
If you're using Tsung to test a Rails site that has CSRF protection, Tsung needs to parse the authenticity_token and submit it when POSTing. I could only find outdated examples. The snippet below works.
<request>
<dyn_variable name="authenticity_token" ></dyn_variable>
<http url="/registrations/new" version="1.1" method="GET"></http>
</request>
<request subst="true">
<http url="/registrations" method="POST" version="1.1"
contents="authenticity_token=%%_authenticity_token%%&amp;first_name=Jane"/>
</request>
@kidbrax
kidbrax / point-in-polygon.rb
Created September 22, 2011 22:43
Check whether a point is within a polygon #ruby
def point_in_polygon?(polygonPoints)
return false if self.latitude.blank? or self.longitude.blank?
polygonPoints.each do |point|
point[0] = point[0].to_f
point[1] = point[1].to_f
end
contains_point = false
i = -1
j = polygonPoints.size - 1
@jose8a
jose8a / Convert MARKDOWN files to HTML
Last active April 26, 2022 09:36
Converting a folder full of markdown files, each linking to each other ... convert those files to HTML, and convert the relative links to point to the new html files. Add code highlighting with highlight.js . Finally serve up the result as a static web site.
Converting md files to html w/highlighting
0a) Create a root directory to pull in all the repos
0b) Recursively clone or pull each repo
$> git clone <repo_url> | git pull on the existing repos
0c) Create a TOC index.html file for the root folder
$> echo '<head>' >> index.html
$> echo '' >> index.html
$> echo '</head>' >> index.html
$> echo '<body>' >> index.html
$> ls >> temp.html
@zachwaugh
zachwaugh / gist:521133
Created August 12, 2010 15:19
Loading rails environment in a script
#!/usr/bin/env ruby
# Load Rails
ENV['RAILS_ENV'] = ARGV[0] || 'production'
DIR = File.dirname(__FILE__)
require DIR + '/../config/environment'
# ... do stuff that requires using your rails models
@antimatter15
antimatter15 / algorithm.pseudo
Created February 16, 2012 03:22
Pseudocode to Graphviz Converter
Place phone call.
Home?
Leave message
Wait for callback
"Would you like to share a meal"
"Would you like to share a meal"
What is the response (A) ?
"Do you enjoy a hot beverage"
What is the response (B) ?
n = 0