Skip to content

Instantly share code, notes, and snippets.

View Seich's full-sized avatar

David Díaz Seich

View GitHub Profile
@Seich
Seich / user.rb
Last active December 11, 2015 12:38
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
@Seich
Seich / toggleable.js
Last active December 10, 2015 22:29
Hiding an element when it loses it's 'focus'
$(".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");
}
});
});
});
@Seich
Seich / gist:4498392
Created January 10, 2013 00:41 — forked from dhh/gist:1014971
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
struct punto {
punto(int x1, int y1) : x(x1), y(y1) {}
int x;
int y;
};
@Seich
Seich / gist:2934088
Created June 15, 2012 01:24
C++ 11 compile line for makefiles.
c11:
g++-4.6 -W -Wall -Wextra -pedantic -std=c++0x *.cc *.h
void setup () {
Serial.begin (9600);
pinMode (12, OUTPUT);
}
void serialEvent() {
digitalWrite(12, HIGH);
delay(2000);
digitalWrite(12, LOW);
Serial.read();
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!
@Seich
Seich / batteryMeter.rb
Created March 3, 2012 19:06
Zsh battery reporting for Ubuntu
# 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
@Seich
Seich / gist:1888634
Created February 23, 2012 00:22
Adding Nodes to Jtree
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();
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, "_" );
}