Skip to content

Instantly share code, notes, and snippets.

View aivascu's full-sized avatar

Andrei Ivascu aivascu

View GitHub Profile
@aivascu
aivascu / fallbackDirective.js
Last active August 29, 2015 14:20
AngularJS directive that shows a placeholder image, using HolderJS, when the image request yielded an error.
// Usage: <img ng-src="{{imageurl || '//:0'}}" ng-fallback="holder.js/210x140/text:No Image" />
'use strict';
(function(angular, Holder){
var fallbackDirective = function () {
return {
link: function (scope, element, attrs) {
element.bind('error', function () {
if (attrs.src !== attrs.ngHolder && Holder != null) {
var src = null;
@aivascu
aivascu / serviceInstall.ps1
Created May 11, 2015 09:10
Installs a windows service on a local/remote machine
param(
[Parameter(Mandatory = $true, Position = 0)]
[string]$ServiceName = $(throw "Service name is required."),
[Parameter(Mandatory = $true, Position = 1)]
[string]$BinPath = $(throw "The service's binary path is required."),
[Parameter(Mandatory = $true, Position = 1)]
[string]$ServiceDisplayName = $(throw "The service's display name is required."),
@aivascu
aivascu / serviceUninstall.ps1
Created May 11, 2015 09:11
Uninstalls a windows service on a local/remote machine
param(
[Parameter(Mandatory = $true, Position = 0)]
[string]$ServiceName,
[Parameter(Mandatory = $false, Position = 1)]
[string]$DeploymentServer
)
function Get-RemoteService(
[string]$serviceName = $(throw "serviceName is required"),
[string]$targetServer = $(throw "targetServer is required"))
@aivascu
aivascu / IsNullOrEmptyExtension.cs
Created June 20, 2015 12:48
LINQ independent IsNullOrEmpty extension class
using System.Collections;
using System.Collections.Generic;
namespace Demo.Utility
{
public static class IsNullOrEmptyExtension
{
public static bool IsNullOrEmpty(this IEnumerable source)
{
if (source != null)
@aivascu
aivascu / plaintextFilter.js
Last active August 29, 2015 14:23
AngularJS filter for removing HTML
// usage: var app = angular.module('app', ['app.filters']);
// {{ expression | plaintext }}
'use strict';
(function(angular) {
var plaintext = function() {
return function(text) {
return String(text).replace(/<[^>]+>/gm, '');
};
};
@aivascu
aivascu / Update-Version.ps1
Last active August 29, 2015 14:24
Updates assembly versions
# Usage: Update-Version.ps1 -Version [-Path] [-Verbose]
# Example: .\Update-Version.ps1 -Version "1.2.3.4" -Path ..\Path\To\Sln -Verbose
param(
[Parameter(Mandatory = $false)]
[string]$Path,
[Parameter(Mandatory = $true)]
[string]$Version)
function Update-AssemblyInfo(
[string]$FilePath = $(throw "FilePath is required"),
@aivascu
aivascu / Program.cs
Last active August 29, 2015 14:24
Get first missing number in an array. (LINQ independent)
using System;
using System.Collections.Generic;
public class Program
{
public static int GetFirstMissingNumber(int[] positions)
{
int maxPositions;
var posMax = 0;
var posCount = 0;
@aivascu
aivascu / ClickOnceIncludeContent.targets
Created August 4, 2015 07:52
Include content files in to ClickOnce
<ItemGroup>
<AdditionalPublishFile Include="$(OutputPath)\**\*.jpg">
<Visible>False</Visible>
</AdditionalPublishFile>
</ItemGroup>
<Target Name="BeforeBuild">
<Touch Files="@(IntermediateAssembly)" />
<CreateItem Include="@(AdditionalPublishFile)" AdditionalMetadata="TargetPath=%(FileName)%(Extension);IsDataFile=false">
<Output TaskParameter="Include" ItemName="_DeploymentManifestFiles" />
</CreateItem>
@aivascu
aivascu / EmployeeBusinessEngineTests.cs
Last active March 25, 2016 11:02
Refactored unit tests
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using NSubstitute;
using NUnit.Framework;
using ProjectPersons.Business.Engines;
using ProjectPersons.Business.Helpers.Abstract;
using ProjectPersons.Business.Helpers.Concrete;
using ProjectPersons.Data.Abstract;
@aivascu
aivascu / MyDbContext.cs
Created April 20, 2016 11:21
DbContext sample on how to initialize a database depending on the build type
public class MyDbContext : DbContext
{
public DbSet<MyClass> MyClasses { get; set; }
protected override void OnModelCreating (DbModelBuilder modelBuilder)
{
base.OnModelCreating (modelBuilder);
modelBuilder.Conventions.Remove<System.Data.Entity.ModelConfiguration.Conventions.PluralizingTableNameConvention> ();
// Add any configuration or mapping stuff here