Skip to content

Instantly share code, notes, and snippets.

View mhenrixon's full-sized avatar
🐢
I may be slow to respond.

Mikael Henriksson mhenrixon

🐢
I may be slow to respond.
View GitHub Profile
@mhenrixon
mhenrixon / Daily WTF!!!?
Created November 16, 2010 07:53
This code should never be written!
if(o.LastAccessed < maxIntegrationTime) {
return true;
}
return false;
@mhenrixon
mhenrixon / if.cs
Created March 2, 2011 20:16
the c# way of doing if statements
if ((order.status != :created) and !(User.Current.IsInRole("Admin")
{
ViewBag.Alert = "This order cannot be changed since work has begun;
Response.Redirect(string.Format("/Orders/", order.Id);
}
require 'client_side_validations/simple_form' if defined?(::SimpleForm)
require 'client_side_validations/formtastic' if defined?(::Formtastic)
# Uncomment the following block if you want each input field to have the validation messages attached.
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
unless html_tag =~ /^<label/
%{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}.html_safe
else
%{<div class="field_with_errors">#{html_tag}</div>}.html_safe
end
@mhenrixon
mhenrixon / formtastic_client_side_validations.rb
Created April 21, 2011 19:19
The code that doesn't work with client side validations
=semantic_form_for [:admin,@frame], validate: true do |f|
=f.inputs do
=f.input :collection
=f.input :collection_id, as: :select, collection: @collections, label: 'Choose Collection'
=f.input :category, as: :select, collection: ['', 'Indoors', 'Outdoors'], label: "Select category"
=f.input :name
=f.buttons
<form accept-charset="UTF-8" action="/orders" class="formtastic order" data-validate="true" id="new_order" method="post" novalidate="novalidate" name="new_order">
<div>
<fieldset>
<legend><span>Select a Store</span></legend>
<ol>
<li class="error">
<label for="order_store">Store</label> <select data-validate="true" id="order_store_id" name="order[store_id]">
<optgroup label="Independant">
<option value ="" />
<option value="2">
@mhenrixon
mhenrixon / extensions.rb
Created May 4, 2011 21:24
active record extensions
class ActiveRecord::Base
def self.has_statuses(*status_names)
validates :status,
presence: true,
inclusion: { in: status_names.to_s}
status_names.each do |status_name|
scope "all_#{status_name}", where(status: status_name)
end
@mhenrixon
mhenrixon / Dog.rb
Created May 9, 2011 17:35
Strange carrierwave insert
class Dog < ActiveRecord::Base
attr_accessible :name, :pictures_attributes
has_many :pictures, as: :attachable
accepts_nested_attributes_for :pictures
end
(function() {
var gs = document.createElement('script'), gsc = document.createElement('div'), interval;
gs.type = 'text/javascript'; gs.async = true; gsc.id = 'getsatisfaction';
gs.src = document.location.protocol + '//s3.amazonaws.com/getsatisfaction.com/javascripts/feedback-v2.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(gs);
(document.getElementsByTagName('body')[0]).appendChild(gsc);
interval = setInterval(function() {
if (window.GSFN !== undefined) {
new GSFN.feedback_widget({
@mhenrixon
mhenrixon / es.sh
Created January 17, 2012 10:56 — forked from jmikola/es.sh
Install ElasticSearch on Ubuntu 11.04
cd ~
sudo apt-get install unzip
sudo apt-get install python-software-properties -y
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo apt-get update
sudo apt-get install sun-java6-jre sun-java6-plugin -y
wget https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.17.6.tar.gz -O elasticsearch.tar.gz
tar -xf elasticsearch.tar.gz
rm elasticsearch.tar.gz
@mhenrixon
mhenrixon / q_export_and_wait.pas
Created April 19, 2012 07:49
How to manually wait for a Jeeves CrystalExportToFile to complete.
// The last parameter is wait and that doesn't work in Windows 7 for some reason. It don't get the completion notification so we wait until the file is ready
CrystalExportToFile(sCrystalTemplate,sFile,sTempDir, sCondStr, false, false,'',false);
while (fileexists(sTempDir+'\'+sFile,true)<>0) do begin
sleep(1000);
end;