Skip to content

Instantly share code, notes, and snippets.

View rickyah's full-sized avatar

Ricardo Amores Hernández rickyah

  • Barcelona
  • 15:39 (UTC +02:00)
  • X @rickyah
View GitHub Profile
@rickyah
rickyah / :rails Add timestamps to logs
Last active October 1, 2015 13:28
Add timestamps and more info to default Rails logger
# Adds timestamps to logs
# put it at the end of environment.rb
module ActiveSupport
class BufferedLogger
def add(severity, message = nil, progname = nil, &block)
return if @level > severity
message = (message || (block && block.call) || progname).to_s
level = {
0 => "DEBUG",
@rickyah
rickyah / :rails :erb RefineryCms locale navigation
Created August 30, 2012 16:50 — forked from errorstudio/_locale_nav.html.erb
Refinery CMS: a list of all frontend locales with links
<ul>
<% Refinery::I18n.config.frontend_locales.each do |locale| %>
<li>
<%= link_to "/#{locale.to_s + request.path}", {:title => Refinery::I18n.locales[locale]} do%>
<span><%= Refinery::I18n.locales[locale] %></span>
<% end -%>
</li>
<% end %>
</ul>
@rickyah
rickyah / GetCurrentMethodName.cs
Created March 28, 2014 11:02
Get the currently executing method name in .NET/Mono
[MethodImpl(MethodImplOptions.NoInlining)]
public string GetCurrentMethodName()
{
StackTrace st = new StackTrace ();
StackFrame sf = st.GetFrame (1);
MethodBase method = sf.GetMethod();
return method.DeclaringType.FullName + ':' + sf.GetMethod().Name;
}
@rickyah
rickyah / BenchmarkProperties.cs
Created April 4, 2014 12:44
Benchmark c# accessors vs member variables
using System;
using System.Diagnostics;
public class TestClass
{
public int member;
public int property {get; set;}
}
@rickyah
rickyah / naming_conventions.md
Last active August 29, 2015 13:58
CSharper_naming_conventions

#C# Naming conventions

Why bother?

Using this naming conventions will allow to know if we are dealing with local variables, private fields, or public data just with a glimpse of the code.

In this code: ¿which variables are internal data to the class and which ones are public?

public void MyMethod(int index)
{
@rickyah
rickyah / gist:10016780
Last active August 29, 2015 13:58
csharper_properties

#C# Properties

Properties are getters & setters but well done.

They require minimal code for setup:

public int MyProperty {get;set;}

This declares a completely functional property. The compiler generates the member to store the property data automatically.

@rickyah
rickyah / gist:10016784
Last active August 29, 2015 13:58
csharper_attributes

#C# Attributes

WIP

Attributes are just meta-data associated to the code.

You can create your own:

  • Create a child class of System.Attribute
  • The name of your attribute class should end with Attribute (convention sufix)
@rickyah
rickyah / podfile_static_lib
Created May 18, 2014 19:06
Remove static lib dependencies when the user project for a CocoaPods is an static lib project itself
# we don't want to link static libs or it will fail to build
# see https://github.com/CocoaPods/CocoaPods/issues/117
targets = [:target1, :target2]
lib_dependencies = ['z']
post_install do |installer|
installer.libraries.select { |i| targets.include? i.target_definition.name.to_sym }.each do |l|
config_file_path = l.library.xcconfig_path
config_file_contents = File.read(config_file_path)
@rickyah
rickyah / MonoBehaviourSingleton.cs
Created June 3, 2015 08:59
MonoBehaviour Singleton
using System;
using UnityEngine;
/// <summary>
/// This is a generic Singleton implementation for Monobehaviours.
/// Create a derived class where the type T is the script you want to "Singletonize"
/// Upon loading it will call DontDestroyOnLoad on the gameobject where this script is contained
/// so it persists upon scene changes.
/// </summary>
/// <remarks>