Skip to content

Instantly share code, notes, and snippets.

View costis's full-sized avatar
🎯
Focusing

Costis Panagiotopoulos costis

🎯
Focusing
View GitHub Profile
@costis
costis / gist:5135502
Last active October 1, 2020 20:32
Copy terminfo entries to remote host

You can copy the necessary terminfo descriptions to remote hosts.

  • On the local system, dump the description to text format:

    infocmp xterm-256color > xterm-256color.ti

    infocmp screen-256color > screen-256color.ti

  • Copy to the remote host and compile:

@costis
costis / gist:4944725
Created February 13, 2013 13:51
Dump Ruby's exceptions tree
exceptions = []
tree = {}
ObjectSpace.each_object(Class) do |cls|
next unless cls.ancestors.include? Exception
next if exceptions.include? cls
next if cls.superclass == SystemCallError # avoid dumping Errno's
exceptions << cls
cls.ancestors.delete_if {|e| [Object, Kernel].include? e }.reverse.inject(tree) {|memo,cls| memo[cls] ||= {}}
end
@costis
costis / sandi_metz_rules_for_developers.md
Last active December 12, 2015 09:49 — forked from sdball/sandi_metz_rules_for_developers.md
Sandi Metz’ rules for developers

Sandi Metz’ rules for developers

  1. Your class can be no longer than a hundred lines of code.
  2. Your methods can be no longer than five lines of code
  3. You can pass no more than four parameters and you can't just make it one big hash.
  4. In your controller, you can only instantiate one object, to do whatever it is that needs to be done.
  5. Your view can only know about one instance variable.
  6. Your Rails view should only send messages to that object i.e., no Demeter violations.[ "thunder dome principal". Translated: one model in, one model out! ]
  7. Rules are meant to be broken if by breaking them you produce better code. [ ...where "better code" is validated by explaining why you want to break the rule to someone else. ]
@costis
costis / gist:4643072
Created January 26, 2013 16:12
MYSQL create UTF8 database

CREATE DATABASE mydb DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;

@costis
costis / gist:4572756
Created January 19, 2013 13:45
Rails Engines producing RSpec
class Engine < ::Rails::Engine
isolate_namespace
config.generators do |g|
g.test_framework :rspec
g.integration_tool :rspec
end
end
require 'factory_girl_rails'
require 'rspec'
require 'rspec-rails'
require 'rspec/mocks/standalone' # => if factories need stubs (for remote services for example)
include FactoryGirl::Syntax::Methods # make FG methods available at top level, so you can do `> create :user`
def reload_factories!
FactoryGirl.instance_variable_set(:@factories, nil) # => clear loaded factories/sequences
# FactoryGirl.instance_variable_set(:@sequences, nil)
@costis
costis / ctags_for_ruby.txt
Created January 4, 2013 14:10
Ctags creation for Ruby projects
# Scan all installed gems - very slow
ctags --extra=+f --exclude=.git --exclude=log -R * gem environment gemdir/gems/*
# Scan only gems from current Gemfile
bundle list --paths=true | xargs ctags --extra=+f --exclude=.git --exclude=log -R *
@costis
costis / gist:4169119
Last active October 13, 2015 08:38
git submodules

How to manage git submodules

Add new

git submodule add http://blah.blha.com/project.git a_project_path
git add *
git commit -m "adding a submodule"

Update

cd a_project_path

git pull

@costis
costis / gist:4131738
Created November 22, 2012 15:34
Make ruby fly
# From:http://alisnic.net/blog/making-your-ruby-fly/
# into ~/.rvmrc
rvm_configure_env=(CFLAGS="-march=core2 -O2 -pipe -fomit-frame-pointer")
# and then
rvm install 1.9.3-turbo --patch falcon
# or better
rvm get head
@costis
costis / gist:4125937
Created November 21, 2012 16:42
Modify Git history
# replace a string occuring to all .yml documents, everywhere in history.
# note: -i "" in sed was needed for OSX. Normally I would write 'sed -i -e "s/foo/bar/g"'.
git filter-branch --tree-filter 'find . -name "*.yml" -exec sed -i "" -e "s/some-config-parameter/new-config-parameter/g" {} \;' HEAD
# the above will create an internal git backup. Delete it with the following command:
git update-ref -d refs/original/refs/heads/master
# create a script with the following contents to change commiter/author name & email.
#!/bin/sh