Skip to content

Instantly share code, notes, and snippets.

@m-radzikowski
m-radzikowski / script-template.sh
Last active November 15, 2024 11:25
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
@hovsater
hovsater / gist:7688474
Last active December 29, 2015 15:09
User-defined command to setup key mappings for RSpec.
function RSpecCommands(bang)
if !a:bang
noremap <Leader>t :!bundle exec rspec %<CR>
noremap <Leader>T :!bundle exec rspec %:<C-R>=line('.')<CR><CR>
else
silent! nunmap <Leader>t
silent! nunmap <Leader>T
endif
endfunction
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<!--
Documented at
http://linux.die.net/man/5/fonts-conf
To check font mapping run the command at terminal
$ fc-match 'helvetica Neue'
@andkerosine
andkerosine / raskell.rb
Created August 15, 2012 05:56
Haskell-like list comprehensions in Ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@
# ~/.gitconfig from @boblet
# initially based on http://rails.wincent.com/wiki/Git_quickstart
[core]
excludesfile = /Users/oli/.gitignore
legacyheaders = false # >git 1.5
quotepath = false
# http://stackoverflow.com/questions/136178/git-diff-handling-long-lines
pager = less -r
# if ↑ doesn’t work, try: pager = less -+$LESS -FRX
#!/bin/sh
#
# new_server.sh
# Author: Sam Soffes
# Created: 02/25/2010
# Updated: 11/04/2010
#
# See my blog post on this script: http://samsoff.es/posts/new-server-script
#
# This script installs everything needed to run a Ruby on Rails application on
@bcalloway
bcalloway / rails-export-csv.rb
Created July 29, 2009 22:08
Use FasterCSV to export an ActiveRecord object in Rails
### /config/environment.rb
config.gem 'fastercsv'
### /config/routes.rb
map.connect '/users/export', :controller => 'users', :action => 'export'
### /app/models/user.rb
# find all students and pass to controller export action for export to csv
def self.find_students
find_by_sql("select students.firstname, students.lastname, students.grade, students.homeroom, students.phone, students.email, students.relationship, users.firstname, users.lastname, accounts.school from students, users, accounts where students.user_id = users.id and accounts.id = users.account_id")
def euclidean_distance(p1,p2)
sum_of_squares = 0
p1.each_with_index do |p1_coord,index|
sum_of_squares += (p1_coord - p2[index]) ** 2
end
Math.sqrt( sum_of_squares )
end
require 'test/unit'
class EuclideanDistanceTest < Test::Unit::TestCase