Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@premsh
premsh / stack-div-float-right.html
Created August 30, 2017 19:44
stack div floating right
<div id="parent" style="width: 80%">
<div id="up" style="float: right; clear: both;">div with id 'up'</div>
<div id="down" style="float: right; clear: both;">div with id 'down'</div>
'parent' div
</div>
@premsh
premsh / merge-two-steams-of-date
Created August 10, 2017 15:54
merge two steams of data and do something different based on input
import { Component } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import 'rxjs/add/observable/interval';
import 'rxjs/add/operator/map';
import 'rxjs/add/observable/merge';
import 'rxjs/add/operator/startWith';
import 'rxjs/add/operator/scan';
import 'rxjs/add/operator/mapTo';
import { Component } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import 'rxjs/add/observable/interval';
import 'rxjs/add/operator/map';
import 'rxjs/add/observable/merge';
import 'rxjs/add/operator/startWith';
import 'rxjs/add/operator/scan';
@Component({
import { Component } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import 'rxjs/add/observable/interval';
import 'rxjs/add/operator/map';
import 'rxjs/add/observable/merge';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
@premsh
premsh / gist:b4b1642f4c09b474485f5c776f8c5abd
Created August 29, 2016 15:16
Angular 1.x directive in TypeScript
class MyDirective implements ng.IDirective {
restrict = 'A';
require = 'ngModel';
templateUrl = 'myDirective.html';
replace = true;
constructor(private $location: ng.ILocationService, private toaster: ToasterService) {
}
link = (scope: ng.IScope, element: ng.IAugmentedJQuery, attrs: ng.IAttributes, ctrl: any) => {
using (var client = new HttpClient())
{
var message = new HttpRequestMessage(HttpMethod.Post, url);
message.Headers.Add("Authorization", authKey);
message.Headers.Add("Audit",auditKey);
message.Content = new StringContent(content, new UTF8Encoding(), "application/json");
var response = client.SendAsync(message).Result;
@premsh
premsh / copyRowSameTable
Created May 19, 2014 14:41
Copy row same table MSSQL
DECLARE @Tablename NVARCHAR(255) = 'MyTable'
DECLARE @IdColumn NVARCHAR(255) = 'MyTableId' -- Primarykey-Column, will be ignored
DECLARE @IdToCopyFrom VARCHAR(255) = '33' -- Copy from this ID
DECLARE @ColName NVARCHAR(255)
DECLARE @SQL NVARCHAR(MAX) = ''
DECLARE Table_Cursor CURSOR FOR
SELECT [B].[Name]
FROM SYSOBJECTS AS [A], SYSCOLUMNS AS [B]
@premsh
premsh / memoryCacheWrapper.cs
Created December 19, 2013 00:17
asp.net MemoryCache class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Caching;
namespace CacheProject
{
public class CacheLayer
{
static readonly ObjectCache Cache = MemoryCache.Default;
@premsh
premsh / jquery replace with
Created December 10, 2013 21:02
Replace the html tag
You can pass a function to .replaceWith [docs]:
$('code').replaceWith(function(){
return $("<pre />", {html: $(this).html()});
});
Inside the function, this refers to the currently processed code element.
Update: There is no big performance difference, but in case the code elements have other HTML children, appending the children instead of serializing them feels to be more correct:
@premsh
premsh / sortJavascriptobjects
Created December 7, 2013 02:29
sort javascript objects
//This will sort your array
function SortByName(a, b){
var aName = a.name.toLowerCase();
var bName = b.name.toLowerCase();
return ((aName < bName) ? -1 : ((aName > bName) ? 1 : 0));
}
array.sort(SortByName);