Skip to content

Instantly share code, notes, and snippets.

Avatar

Mikael Henriksson mhenrixon

View GitHub Profile
View Chilkat verify - Fail
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)
{
View IHideObjectMembers
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 Nov 16, 2010
This code should never be written!
View Daily WTF!!!?
if(o.LastAccessed < maxIntegrationTime) {
return true;
}
return false;
@mhenrixon
mhenrixon / JobRegistry.cs
Created Jan 10, 2011
A quick way to setup quartz with structuremap
View JobRegistry.cs
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 Mar 2, 2011
the c# way of doing if statements
View if.cs
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);
}
View client_side_validations.rb
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 Apr 21, 2011
The code that doesn't work with client side validations
View formtastic_client_side_validations.rb
=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
View order.html
<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
active record extensions
View extensions.rb
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
Strange carrierwave insert
View Dog.rb
class Dog < ActiveRecord::Base
attr_accessible :name, :pictures_attributes
has_many :pictures, as: :attachable
accepts_nested_attributes_for :pictures
end