Skip to content

Instantly share code, notes, and snippets.

@dadarek
dadarek / quiet_assets.rb
Created May 20, 2015 14:52
Remove assets from rails logs
if Rails.env.development?
Rails.application.assets.logger = Logger.new('/dev/null')
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'] =~ %r{^/assets/}
call_without_quiet_assets(env)
ensure
Rails.logger.level = previous_level
end
@dadarek
dadarek / interfaces.java
Created June 7, 2014 01:05
Cornering dependencies
interface Socket {
void send(String string);
void close();
}
class ClientHandler {
private Socket socket;
public ClientHandler( Socket socket ){
@dadarek
dadarek / di.rb
Created November 15, 2013 19:15
Dependency Injection Example
# DEPENDENCY INJECTION
class A
def initialize(helper)
end
def doSomething
helper.someFunction
end
@dadarek
dadarek / gist:7343633
Created November 6, 2013 20:37
brew doctor
Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.
Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
/Users/dariusz/.rvm/bin/erb-ree-1.8.7-2011.12@ops-config
class Game
def initialize( printer, logicMachine )
end
def go
while logicMachine.continue?
printer.puts( "We are still playing the game." )
%p= @hey
@dadarek
dadarek / SomeClass-bad.cs
Created August 20, 2013 16:23
Command-Query Violation
class SomeClass{
private int reason;
public bool Go(){
int value = SomeBigCalculation();
if( value > 5 ){
this.reason = "Too Big";
return true;
@dadarek
dadarek / SomeClass-bad.cs
Created August 20, 2013 16:16
How to corner dependencies that are hard to mock or extract interface.
class SomeClass{
private BigHorrificMonsterClass myBaby = new BigHorrificMonsterClass();
public int DoSomething( int value ){
int cradled = myBaby.cradle( value );
return value + cradled;
}
}
@dadarek
dadarek / Hierarchy.md
Last active December 21, 2015 09:09
How to structure your test project files.
  • Project 1

    • Folder 1
      • Class1 cs
      • Class2 cs
    • Class3 cs
  • Project 1 Tests

    • Folder 1
  • Class1_Test.cs

@dadarek
dadarek / SomeClass-bad.cs
Last active December 21, 2015 09:09
How to inject globals without affecting client code.
class SomeClass{
private int someValue;
public SomeClass( int someValue ){
this.someValue = someValue;
}
public int SomeFunction(){
return someValue + GlobalReference.someFunction();
}