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
public static string OpenSslVerify(string publicKeyFile, string signedContent)
{
var pkey = new PublicKey();
pkey.LoadOpenSslPemFile(publicKeyFile);
string pkeyXml = pkey.GetXml();
var rsa = new Rsa();
bool success = rsa.UnlockComponent("30-day trial");
if (success != true)
{
using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
namespace Moq
{
[EditorBrowsable(EditorBrowsableState.Never)]
public interface IHideObjectMembers
{
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
@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 / JobRegistry.cs
Created January 10, 2011 11:03
A quick way to setup quartz with structuremap
internal class JobRegistry :Registry
{
public JobRegistry()
{
ForSingletonOf<PlaynGO.Common.InversionOfControl.IContainer>().Use<PlaynGO.StructureMap.Container>();
ForSingletonOf<IJobFactory>().Use<WpsJobFactory>();
var col = new NameValueCollection();
ForSingletonOf<ISchedulerFactory>().Use<StdSchedulerFactory>().Ctor<NameValueCollection>("props").Is(ctx =>
{
@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