Skip to content

Instantly share code, notes, and snippets.

@ioab
ioab / BinarySearch.cpp
Last active August 29, 2015 14:17
BinarySearch Algorithm
/**
* @note:
* Works properly with numbers.
* other types may have to define another equality criteria.
*
* @return: Item index if found. -1 otherwise.
*/
template<typename T>
int BinarySearch(T * arr, int size, T searchKey)
{
@ioab
ioab / WPFUnhandledException.cs
Created April 21, 2015 14:25
Catching Unhandled Exceptions in WPF Applications
using System;
using System.Windows;
using System.Windows.Threading;
namespace __temp_WPF
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
@ioab
ioab / BinomialDistribution.cs
Created May 27, 2015 20:01
Bionomial Distribution Implementation
using System;
namespace Bionomial_Distribution
{
class Program
{
static void Main(string[] args)
{
BionomialDistribution b = new BionomialDistribution();
@ioab
ioab / FileMaxSizeAttribute.cs
Last active September 25, 2017 01:30
File max size validation attribute for ASP.NET MVC
namespace App.Infrastructure
{
public class FileMaxSizeAttribute : ValidationAttribute
{
public FileMaxSizeAttribute(int maxSize = 10 * 1024 * 1024, string errorMessage = "{0} is not a valid file.")
: base(errorMessage)
{
// 10 MB by default //
this._maxSize = maxSize;
}
@ioab
ioab / ValidatableModel.cs
Last active September 28, 2015 20:52
A simple validatable model class.
/// <summary>
/// A simple Model with validation logic built within it.
/// Another approach of validation besides &quot; Data Annotations &quot; is to implement IValidatableObject interface.
/// </summary>
public class User : IValidatableObject
{
public int Age { get; set; }
public string Name { get; set; }
@ioab
ioab / naive_primes.rb
Created May 6, 2016 11:22
simple ruby class for testing primaility.
class PrimesTester
def initialize number
@number = number
end
attr_accessor :number
def prime?
# test primaility for the input number.