Skip to content

Instantly share code, notes, and snippets.

View jmelosegui's full-sized avatar

Juan Manuel Elosegui jmelosegui

View GitHub Profile
@jmelosegui
jmelosegui / ufnAddBusinessDays.sql
Created March 17, 2016 18:23
ufnAddBusinessDays SqlServer function
CREATE FUNCTION [dbo].[ufnAddBusinessDays]
(
@Date DATE,
@n int -- Number of days to add or substract
)
RETURNS DATE
AS
BEGIN
DECLARE @d INT,@f INT,@DW INT;
Set @f = CAST(abs(1^SIGN(DATEPART(DW, @Date)-(7-@@DATEFIRST))) as bit)
@jmelosegui
jmelosegui / javascript-string-format.js
Last active September 12, 2016 16:32
Mimicking the .Net string format.
/*
This will format a string mimicking the .Net string format.
ie: format('test {0} - {1}', 'value 1', 'value 2');
*/
function format(value) {
var args = Array.prototype.slice.call(arguments, 1);
return value.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
@jmelosegui
jmelosegui / Country.sql
Last active October 4, 2016 16:48
A Microsoft Sql Server script to add a country table to your database
IF OBJECT_ID('[dbo].[Country]', 'U') IS NOT NULL
DROP TABLE [dbo].[Country]
CREATE TABLE [dbo].[Country]
(
Id int NOT NULL IDENTITY(1,1),
Name varchar(80) NOT NULL,
DisplayName varchar(80) NOT NULL,
Iso char(2) NOT NULL,
Iso3 char(3) NULL,
@jmelosegui
jmelosegui / GetPicasaUserByEmail.cs
Last active October 4, 2016 19:35
Gets a Picasa user, hence a google user, using an email address.
using System;
using System.Collections.Generic;
using System.IO;;
using System.Net;
using System.Xml.Serialization;
namespace ConsoleApplication1
{
class Program
{
@jmelosegui
jmelosegui / Reset-MySqlRootPassword.ps1
Last active January 2, 2017 13:26
Resetting the Root Password on a Windows System
<#
.SYNOPSIS
Automation of the steps described on https://dev.mysql.com/doc/mysql-windows-excerpt/5.7/en/resetting-permissions-windows.html
to reset the Root Password of MySql server on a Windows system.
.PARAMETER MysqlServiceName
The MySql service's name (e.g. MySQL56).
.PARAMETER RootPassword
The password for the root user
#>
Param(
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Input;
using static PInvoke.User32;
using static PInvoke.Kernel32;
namespace WpfApplication1
{
##-----------------------------------------------------------------------
## <copyright file="ApplyVersionToAssemblies.ps1">(c) Microsoft Corporation. This source is subject to the Microsoft Permissive License. See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx. All other rights reserved.</copyright>
##-----------------------------------------------------------------------
# Look for a 0.0.0.0 pattern in the build number.
# If found use it to version the assemblies.
#
# For example, if the 'Build number format' build process parameter
# $(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)
# then your build numbers come out like this:
# "Build HelloWorld_2013.07.19.1"
@jmelosegui
jmelosegui / Install-Npm.ps1
Created April 25, 2017 18:18
Install npm in the UserProfile Folder if it does not exist.
[CmdletBinding()]
param(
[switch]$force
)
$userProfileDir = $env:USERPROFILE
$NodeDir = Join-Path $userProfileDir "Node"
if($force -and (Test-Path $NodeDir)){
@jmelosegui
jmelosegui / Odbccp32.cs
Created May 15, 2017 17:40
P/Invoke Odbccp32
public class Odbccp32
{
/// <summary>
/// From sql.h
/// </summary>
private const int SQL_MAX_MESSAGE_LENGTH = 512;
[DllImport(nameof(Odbccp32), CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SQLGetInstalledDrivers(char[] lpszBuf, ushort cbufMax, out ushort pcbBufOut);
@jmelosegui
jmelosegui / Odbccp32.cs
Created May 15, 2017 17:40
P/Invoke Odbccp32
public class Odbccp32
{
/// <summary>
/// From sql.h
/// </summary>
private const int SQL_MAX_MESSAGE_LENGTH = 512;
[DllImport(nameof(Odbccp32), CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SQLGetInstalledDrivers(char[] lpszBuf, ushort cbufMax, out ushort pcbBufOut);