Skip to content

Instantly share code, notes, and snippets.

View rohit-lakhanpal's full-sized avatar

Rohit Lakhanpal rohit-lakhanpal

  • Melbourne, VIC, Australia
  • 01:57 (UTC +10:00)
View GitHub Profile
@rohit-lakhanpal
rohit-lakhanpal / FactoryPattern.cs
Last active April 19, 2016 03:09
Patterns - Factory Pattern: Provides an interface for creating families of related or dependent objects without specifying their concrete classes.
using System;
namespace DesignPatterns.Factory.Structural
{
/// <summary>
/// MainApp startup class for Structural
/// Factory Method Design Pattern.
/// </summary>
class MainApp
{
@rohit-lakhanpal
rohit-lakhanpal / FactoryPatternImplementation.cs
Created April 19, 2016 03:20
Patterns - Factory Pattern (Real World Example): Provides an interface for creating families of related or dependent objects without specifying their concrete classes.
using System;
using System.Collections.Generic;
namespace DesignPatterns.Factory.RealWorld
{
/// <summary>
/// MainApp startup class for Real-World
/// Factory Method Design Pattern.
/// </summary>
class MainApp
@rohit-lakhanpal
rohit-lakhanpal / BuilderPattern.cs
Created April 19, 2016 03:28
Patterns - Builder Pattern: Separate the construction of a complex object from its representation so that the same construction process can create different representations.
using System;
using System.Collections.Generic;
namespace DesignPatterns.Builder.Structural
{
/// <summary>
/// MainApp startup class for Structural
/// Builder Design Pattern.
/// </summary>
public class MainApp
@rohit-lakhanpal
rohit-lakhanpal / BuilderPatternImplementation.cs
Created April 19, 2016 04:29
Patterns - Builder Pattern (Real World Example): Separate the construction of a complex object from its representation so that the same construction process can create different representations.
using System;
using System.Collections.Generic;
namespace DesignPatterns.Builder.RealWorld
{
/// <summary>
/// MainApp startup class for Structural
/// Builder Design Pattern.
/// </summary>
public class MainApp
@rohit-lakhanpal
rohit-lakhanpal / ModulePattern.js
Created April 19, 2016 04:43
JS-Module Pattern: Module pattern is used to further emulate the concept of classes in such a way that we're able to include both public/private methods and variables inside a single object, thus shielding particular parts from the global scope. What this results in is a reduction in the likelihood of our function names conflicting with other fu…
var testModule = (function () {
var counter = 0;
return {
incrementCounter: function () {
return counter++;
},
@rohit-lakhanpal
rohit-lakhanpal / RevealingModulePattern.js
Created April 19, 2016 04:54
JS-Revealing Module Pattern: Shopping basket implemented using this pattern. The module itself is completely self-contained in a global variable called basketModule. The basket array in the module is kept private and so other parts of our application are unable to directly read it. It only exists with the module's closure and so the only methods…
var basketModule = (function () {
// privates
var basket = [];
function doSomethingPrivate() {
//...
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>
Apache Web Server <!--#echo var="SCRIPT_NAME" -->
</title>
</head>
<body>
@rohit-lakhanpal
rohit-lakhanpal / CheckJsonValueFromRedis.ps1
Created November 3, 2016 23:57
This PowerShell script pretty prints JSON values from a REDIS cache.
# Define redis host & auth credentials
$redisHost = "redis.local"
$redisAuth = "redispwd"
# Define per site variables stored in redis
$sites = @("server-01","server-01")
# Define function to Pretty Print Json (and replace escaped json string)
function CleanJson($data)
{
@rohit-lakhanpal
rohit-lakhanpal / InvokePowershellAndSleep.ps1
Created November 4, 2016 00:24
This powershell script is able to invoke another powershell script every 90 seconds & pipe the output to a file
# This function generates a new filename based on the current datetime
function GenerateFileNamePerHour
{
# Store the current date in a variable
$cDate = Get-Date
$val = ("{0}_{1}_{2}-{3}00HRS.log" -f $cDate.Day, $cDate.Month, $cDate.Year, $cDate.Hour)
return $val
}
# This script will run till the 328th day of the year
<?xml version="1.0" encoding="UTF-8" ?>
<Response>
<Dial>
<Conference waitUrl="http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient">pv-conference</Conference>
</Dial>
</Response>