Skip to content

Instantly share code, notes, and snippets.

@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
@jgornick
jgornick / configure-make-make-install.yaml
Last active June 8, 2023 16:13
Ansible: ./configure, make, make install
# This works
- name: Install unixODBC
command: sudo {{ item }} chdir="/tmp/{{ mysql_odbc_unixodbc_url | basename | replace('.tar.gz', '') }}"
with_items:
- ./configure --prefix=/usr/local
- make
- make install
# This _doesn't_ work
# Why doesn't the chdir option get recognized?
@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
@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; }
@brianpetro
brianpetro / rails-4-new-options
Created April 28, 2015 18:11
Command line options for ` rails new --help ` (Rails 4.2). Useful for planning new Ruby on Rails app. 'Where can I find options for “rails new” command?'
Because I couldn't find these with a quick Google search on 28 April 2015:
Usage:
rails new APP_PATH [options]
Options:
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
# Default: /home/brian/.rvm/rubies/ruby-2.2.0/bin/ruby
-m, [--template=TEMPLATE] # Path to some application template (can be a filesystem path or URL)
[--skip-gemfile], [--no-skip-gemfile] # Don't create a Gemfile
@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.
@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
@drernie
drernie / csvtomap.go
Created March 10, 2017 22:48
Golang Convert CSV Records to Dictionaries using Header Row as Keys
// CSVToMap takes a reader and returns an array of dictionaries, using the header row as the keys
func CSVToMap(reader io.Reader) []map[string]string {
r := csv.NewReader(reader)
rows := []map[string]string{}
var header []string
for {
record, err := r.Read()
if err == io.EOF {
break
}
@bbonamin
bbonamin / test_rails_exists.rb
Created March 18, 2020 22:51
Rails EXISTS() subquery
# https://github.com/rails/rails/pull/29619#issuecomment-392583498
# Better approach than http://codesnik.github.io/rails/2015/09/03/activerecord-and-exists-subqueries.html
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', '5.2'
gem 'pg'
gem 'pry'