Skip to content

Instantly share code, notes, and snippets.

Phil Hansch phansch

Block or report user

Report or block phansch

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@phansch
phansch / GitHub.PowerShell_profile.ps1
Created Oct 1, 2012
My custom PowerShell prompt
View GitHub.PowerShell_profile.ps1
function shorten-path([string] $path) {
$loc = $path.Replace($HOME, '~')
# remove prefix for UNC paths
$loc = $loc -replace '^[^:]+::', ''
# make path shorter like tabs in Vim,
# handle paths starting with \\ and . correctly
return ($loc -replace '\\(\.?)([^\\])[^\\]*(?=\\)','\$1$2')
}
function prompt {
@phansch
phansch / setup-system.sh
Last active Dec 25, 2015
Custom setup script.
View setup-system.sh
#!/bin/bash
# Author: Philipp Hansch
#
# This script assumes Linux Mint 15 Xfce as a base distribution
# Make sure you have access to this script when you setup your system
# Use at your own risk.
aptget='sudo apt-get'
gh_user='phansch'
@phansch
phansch / jekyll-mentos-error.md
Last active Dec 30, 2015
Fixing my local jekyll setup (pygments.rb-0.5.0/lib/pygments/popen.rb:358:in `rescue in get_header': Failed to get header. (MentosError))
View jekyll-mentos-error.md

Jekyll failing with:

Liquid Exception: Failed to get header. in _posts/filename.md/#excerpt
/home/philipp/.rvm/gems/ruby-2.0.0-p247@global/gems/pygments.rb-0.5.0/lib/pygments/popen.rb:358:in `rescue in get_header': Failed to get header. (MentosError)
        from /home/philipp/.rvm/gems/ruby-2.0.0-p247@global/gems/pygments.rb-0.5.0/lib/pygments/popen.rb:338:in `get_header

Tracked it down to mentos.py. Running mentos.py gave me the following error:

$ python mentos.py
@phansch
phansch / gist:8617494
Last active Jan 4, 2016
class-book.rb stack trace
View gist:8617494
$ bin/shoes samples/class-book.rb
NoMethodError: undefined method `[]' for #<Shoes::Link:0x1304ff98>
normalize_style at /home/philipp/code/shoes4/lib/shoes/dsl.rb:75
each at org/jruby/RubyArray.java:1613
normalize_style at /home/philipp/code/shoes4/lib/shoes/dsl.rb:74
span at /home/philipp/code/shoes4/lib/shoes/dsl.rb:463
method_missing at /home/philipp/code/shoes4/lib/shoes/url.rb:22
table_of_contents at /home/philipp/code/shoes4/samples/class-book.rb:21
incident at /home/philipp/code/shoes4/samples/class-book.rb:32
call at org/jruby/RubyProc.java:271
View stuff.rb
text_styles = %w(code del em ins sub sup strong)
text_styles.each do |m|
para = app.app.para(app.app.send(m, m, stroke: '#ccc'))
expect(para.text).to eq(m)
end
@phansch
phansch / uniqueness_validation.rb
Last active Jan 6, 2017
Rails: Validating uniqueness without saving
View uniqueness_validation.rb
# Had to do this for an importer tool that was being converted to a three-step validation-feedback-persist process
# Rails does not support uniqueness validation for a custom collection of unsaved ActiveRecord models
# Maybe someone finds this useful
def validate_uniqueness
ActiveRecord::Base.transaction do
@unsaved_entities.each do |entity|
entity.object.save # Executes validations/callbacks
entity.successful = entity.object.valid?
end
View association_testcase.rb
# Run with `ruby association_testcase.rb`
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
@phansch
phansch / .pryrc
Last active Aug 21, 2018
Colored Pry prompt including Rails environment and app name
View .pryrc
def formatted_env
case Rails.env
when 'production'
bold_upcased_env = Pry::Helpers::Text.bold(Rails.env.upcase)
Pry::Helpers::Text.red(bold_upcased_env)
when 'staging'
Pry::Helpers::Text.yellow(Rails.env)
when 'development'
Pry::Helpers::Text.green(Rails.env)
else
@phansch
phansch / yardoc_cheatsheet.md
Last active Apr 5, 2020 — forked from chetan/yardoc_cheatsheet.md
Improved YARD cheatsheet
View yardoc_cheatsheet.md
You can’t perform that action at this time.