Skip to content

Instantly share code, notes, and snippets.

View SafeerH's full-sized avatar

Safeer Hussain SafeerH

View GitHub Profile
@SafeerH
SafeerH / IPAddressDbFunctions.cs
Created June 16, 2022 17:17
.NET 6 / EF Core - Add IPAddress DbFunctions (works with Npgsql 6 - PostgreSQL)
public static class IPAddressDbFunctions
{
/// <summary>
/// Translates to (in PostgreSQL):
/// <code>
/// ('[address]'::inet &amp; '[subnetMask]'::inet)
/// </code>
/// </summary>
// ('[address]'::inet & '[subnetMask]'::inet)
public static IPAddress GetNetworkIP(IPAddress address, IPAddress subnetMask) => throw new NotSupportedException();
@SafeerH
SafeerH / retry.ts
Created April 22, 2019 06:22
TypeScript retry async helper
async retryAsync<T>(fn: () => Promise<T>, retryCount: number = 3, retryInterval: number = 1000): Promise<T> {
let retries = -1;
do {
try {
retries++;
return await fn();
} catch (error) {
if (retries === retryCount) {
throw error;
}
@SafeerH
SafeerH / HTML-Colour-Palette.html
Last active August 30, 2017 19:02
HTML colour palette (Javascript/CSS)
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<style>
#container {
display: inline-block;
position: relative;
}
@SafeerH
SafeerH / SQL-CopyTableBetweenDBs.sql
Created August 28, 2017 07:59
Copy table data between databases
SET IDENTITY_INSERT [mydb_to].dbo.[A] ON
INSERT INTO [mydb_to].dbo.[A]( col1, col2, col3, ..., coln ) --List the names of columns
SELECT * FROM [mydb_from].dbo.[A] WHERE reqid = 201
SET IDENTITY_INSERT [mydb_to].dbo.[A] OFF
@SafeerH
SafeerH / add-fontawesome.md
Created October 15, 2016 12:50
generator-gulp-angular - How to add fontawesome?

How to add fontawesome?

First, you need install fontawesome through bower

bower install fontawesome

Next, you need add to your scss file this lines (please, check the paths if you

@SafeerH
SafeerH / ExtractHttpOnlyCookie.cs
Last active April 23, 2021 19:24
Extract HttpOnly cookies (can be with WebBrowser control)
using System.Runtime.InteropServices;
public class WebHelper {
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool InternetGetCookieEx(string pchURL, string pchCookieName, StringBuilder pchCookieData, ref uint pcchCookieData, int dwFlags, IntPtr lpReserved);
const int INTERNET_COOKIE_HTTPONLY = 0x00002000;
public static string GetGlobalCookies(string uri)
{
@SafeerH
SafeerH / same-password.directive.js
Created February 22, 2016 17:08
`samePassword` is a directive with the purpose to validate a password input based on the value of another input. When both input values are the same the inputs will be set to valid.
(function() {
'use strict';
angular
.module('triangular.directives')
.directive('triSamePassword', samePassword);
/* @ngInject */
function samePassword() {
// Usage:
@SafeerH
SafeerH / GetQueryString.js
Created September 7, 2015 11:49
Get query string from JavaScript
function getQueryString() {
var result = {}, queryString = location.search.slice(1),
re = /([^&=]+)=([^&]*)/g, m;
while (m = re.exec(queryString)) {
result[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
}
return result;
}
@SafeerH
SafeerH / JsStringExtensions.js
Last active August 29, 2015 14:23
JavaScript Extensions (String.Format)
/* Format strings in JavaScript
* Usage:
* > "Hello {0}!".format('Safeer'); // Hello Safeer!
*
* > var str = "{0} is one of the most popular programming languages in the world. \
* This {1} contains some extension methods that can be used in your {0} code.";
* str.format('JavaScript', 'Gist');
*
*/
String.prototype.format = function() {
@SafeerH
SafeerH / EmailService.cs
Created May 20, 2015 05:48
Simple SMTP Email Service [for ASP.NET 5 (vNext)]
using System;
using System.Net.Mail;
using Microsoft.Framework.ConfigurationModel;
namespace Mzmsh.SimpleSmtpEmail
{
public class EmailService
{
private readonly IConfiguration _config;
private readonly EmailSettings _settings;