Skip to content

Instantly share code, notes, and snippets.

@hrj
hrj / alias.md
Last active November 29, 2023 09:50
pwd alias hell

TL;DR

When you are in a shell in Linux, you may be led to believe you are in directory xyz but might actually be in directory pqr.


Demonstration

In a terminal,

@parsonsmatt
parsonsmatt / gist:f64393b9349592b6f1c1
Last active August 28, 2020 17:36
class composition in ruby
# In Haskell, you write a function like this:
# f :: a -> b
# which reads as "f is a function from type a to b"
#
# Function composition allows you to chain functions together,
# building more powerful and complex composite functions from
# simpler component functions.
#
# OOP does not have a similar mechanism. Composition in OOP seems
# to mostly be limited to aggregation and delegation, neither of
@domgetter
domgetter / hash_compose.rb
Last active August 29, 2015 14:23
Hash#compose
# Since a key-value store is a finite, discrete function, and functions
# can be composed, then Hashes can be composed.
#
# The syntactic sugar for calling lambdas, accessing array values, and
# other objects which have a #[] method allow composition of Hashes
# with all sorts of objects and contexts with the same implementation.
#
# Play with it at https://eval.in/388458
#
class Hash
@NigoroJr
NigoroJr / sort_du.rb
Created June 9, 2015 01:35
Simple script that sorts the output from du
#!/usr/bin/env ruby
# A program that sorts the output from the command `du -h'
# Use it like: du -h . | $PROGRAM_NAME [-r|--reverse]
SUFFIX = {
'K' => 1E3,
'M' => 1E6,
'G' => 1E9,
'T' => 1E12,
@junegunn
junegunn / vimawesome.vim
Last active September 1, 2024 11:18
Plugin completion using VimAwesome API
" ----------------------------------------------------------------------------
" vimawesome.com
" ----------------------------------------------------------------------------
function! VimAwesomeComplete() abort
let prefix = matchstr(strpart(getline('.'), 0, col('.') - 1), '[.a-zA-Z0-9_/-]*$')
echohl WarningMsg
echo 'Downloading plugin list from VimAwesome'
echohl None
ruby << EOF
require 'json'
@ttscoff
ttscoff / copy.bash
Last active February 20, 2025 09:33
Intelligently copy command results, text file, or raw input/arguments to OS X clipboard
copy() {
if [[ $1 =~ ^-?[hH] ]]; then
echo "Intelligently copies command results, text file, or raw text to"
echo "OS X clipboard"
echo
echo "Usage: copy [command or text]"
echo " or pipe a command: [command] | copy"
return
fi
@jdickey
jdickey / Entity named Post in namespace DIDN'T work.md
Last active August 29, 2015 14:17
Simply subtle namespacing clusterfox FIXED

There once was a project that made extensive use of Pivotal's "Unbuilt Rails Dependency" pseudo-Gem architectural feature. After realising that that was far more limited in its applicable use cases than hoped, efforts were made to claw those back into namespaced classes within the main Rails app.

This was generally successful for a while. The use-case actions/service layer and one of the two core entities, Users, worked Just Fine. When work began on the Post entity, however, increasing forward progress was abruptly halted by a weird error.

Given the files spec/entities/post_spec.rb and app/entities/post.rb as below, running bundle exec rspec spec/entities/post_spec.rb gives the following output

Coverage re
@mvaneijgen
mvaneijgen / Scale resolution.scpt
Last active March 26, 2023 10:46
Change screen resolution AppleScript
local index1, index2
set index1 to 3 -- 1920 x 1200
set index2 to 4 -- 1280 x 800
-- Launch "System Preferences", open the "Displays" options and change to the "Display" tab
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.displays"
reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays"
@dinks
dinks / hearts_formatter.rb
Last active February 6, 2023 13:18
Hearts Formatter
require 'rspec/core/formatters/base_text_formatter'
# Custom Rspec formatter
# bundle exec rspec --require ./hearts_formatter.rb --format HeartsFormatter
#
class HeartsFormatter < RSpec::Core::Formatters::BaseTextFormatter
DOT_SUCCESS = "💚"
DOT_PENDING = "💛"
DOT_FAILURE = "💔"