This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
after_create :create_profile | |
has_one :user_profile, :dependent => :destroy | |
def create_profile | |
self.build_user_profile | |
self.user_profile.save(:validate => false) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(".userMenu a").on("click", function() { | |
$(".loginForm").stop().fadeToggle(100, "linear", function() { | |
$("body").on("click.loginform", function(e) { | |
if($(e.target).parents('.loginForm, .userMenu').length === 0) { | |
$('.loginForm').fadeToggle(100); | |
$("body").off(".loginform"); | |
} | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# autoload concerns | |
module YourApp | |
class Application < Rails::Application | |
config.autoload_paths += %W( | |
#{config.root}/app/controllers/concerns | |
#{config.root}/app/models/concerns | |
) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct punto { | |
punto(int x1, int y1) : x(x1), y(y1) {} | |
int x; | |
int y; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c11: | |
g++-4.6 -W -Wall -Wextra -pedantic -std=c++0x *.cc *.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup () { | |
Serial.begin (9600); | |
pinMode (12, OUTPUT); | |
} | |
void serialEvent() { | |
digitalWrite(12, HIGH); | |
delay(2000); | |
digitalWrite(12, LOW); | |
Serial.read(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "serialport" | |
@rfid_reader = SerialPort.new 4 # Open COM 5 | |
@arduino = SerialPort.new 2 # Open COM 3 | |
@valid_ids = ['4500B8D690BB'] | |
def readRFID | |
rfid = @rfid_reader.gets | |
rfid.strip! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
# Get the current battery status percentage. | |
battery_status = `acpi` | |
charge = battery_status.match(/\d*%/)[0].chop.to_i | |
# Calculate the number of charged slots. | |
total_slots = 10 | |
filled = "▸" * (charge/total_slots).ceil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); | |
DefaultMutableTreeNode root = (DefaultMutableTreeNode)model.getRoot(); | |
DefaultMutableTreeNode c1 = new DefaultMutableTreeNode("Cruce #1"); | |
c1.add(new DefaultMutableTreeNode("Child 1")); | |
root.add(c1); | |
model.reload(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string MakeValidFileName( string name ) | |
{ | |
string invalidChars = Regex.Escape( new string( Path.GetInvalidFileNameChars() ) ); | |
string invalidReStr = string.Format( @"[{0}]+", invalidChars ); | |
return Regex.Replace( name, invalidReStr, "_" ); | |
} |