Skip to content

Instantly share code, notes, and snippets.

View lankaapura's full-sized avatar
👨‍💻
_

Priyantha Lankapura lankaapura

👨‍💻
_
View GitHub Profile
@lankaapura
lankaapura / Samples.JS
Created March 11, 2016 09:11
JQuery 3 Samples
////// 1.1 FOR...OF LOOP
// let’s say that you want to assign an ID to each input element of a page
//OLD
var $inputs = $('input');
for (var i = 0; i < $inputs.length; i++) {
$inputs[i].id = 'input-' + i;
}
Import-Module -Name D:\Temp\ACME-posh\ACMEPowerShell.psd1
$domain = "mydomain.com"
$certificiatePassword = "abcd1234"
$email = "letsencrypt@mydomain.com"
$vault = "D:\Vault\{0}\{1}" -f $domain, [guid]::NewGuid()
mkdir $vault
cd $vault
Initialize-ACMEVault -BaseURI https://acme-v01.api.letsencrypt.org/
New-ACMERegistration -Contacts mailto:$email
@lankaapura
lankaapura / evenmore.js
Last active July 13, 2016 09:02
generate random binary array and Inverse
var ar = getRandomArrayWithInverse(5);
console.log(ar.array);
console.log(ar.reverse);
function getRandomArrayWithInverse(size) {
var randomArray = [];
var inversedArray = [];
for (index = 0; index < size; index++) {
@lankaapura
lankaapura / TSQL-to-POCO
Created March 6, 2017 07:46 — forked from joey-qc/TSQL-to-POCO
A simple TSQL script to quickly generate c# POCO classes from SQL Server tables and views. You may tweak the output as needed. Not all datatypes are represented but this should save a bunch of boilerplate coding. USAGE: Run this query against the database of your choice. The script will loop through tables, views and their respective columns. Re…
declare @tableName varchar(200)
declare @columnName varchar(200)
declare @nullable varchar(50)
declare @datatype varchar(50)
declare @maxlen int
declare @sType varchar(50)
declare @sProperty varchar(200)
DECLARE table_cursor CURSOR FOR
@lankaapura
lankaapura / guard.ts
Created September 28, 2017 12:13
Typescript guard
export function guard() {
return function (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>) {
const originalMethod = descriptor.value;
descriptor.value = function (...args: any[]) {
return false ? originalMethod.apply(this, args) : console.log('not authorized.');
};
return descriptor;
};
@lankaapura
lankaapura / c
Last active December 10, 2017 02:59
export const authConfig: AuthConfig = {
// Url of the Identity Provider
issuer: "https://demo.identityserver.io",
requireHttps: true,
// URL of the SPA to redirect the user to after login
redirectUri: "http://localhost:2020/",
// URL of the SPA to redirect the user after silent refresh
silentRefreshRedirectUri: "http://localhost:2020/silent-refresh.html",
function CopyToClipBoardHandler(value) {
const copyListener = event => {
document.removeEventListener('copy', copyListener, true);
event.preventDefault();
const clipboardData = event.clipboardData;
clipboardData.clearData();
clipboardData.setData('text/plain', value);
};
document.addEventListener('copy', copyListener, true);
document.execCommand('copy');
<!-- 1. Define some markup -->
<div id="btn" data-clipboard-text="1">
<span>Copy</span>
</div>
<!-- 2. Include library -->
<script src="clipboard.min.js"></script>
<!-- 3. Instantiate clipboard by passing a HTML element -->
<script>
@lankaapura
lankaapura / SemverSort.ps1
Created February 12, 2018 09:33 — forked from jageall/SemverSort.ps1
Sorts semver in powershell
#powershell script port of https://github.com/maxhauser/semver/
function toSemVer($version){
$version -match "^(?<major>\d+)(\.(?<minor>\d+))?(\.(?<patch>\d+))?(\-(?<pre>[0-9A-Za-z\-\.]+))?(\+(?<build>[0-9A-Za-z\-\.]+))?$" | Out-Null
$major = [int]$matches['major']
$minor = [int]$matches['minor']
$patch = [int]$matches['patch']
if($matches['pre'] -eq $null){$pre = @()}
else{$pre = $matches['pre'].Split(".")}