Skip to content

Instantly share code, notes, and snippets.

@h09shais
h09shais / ImageGallery.js
Last active August 16, 2018 15:15
React Stateless Functional Component - Image Gallery
// App.js
import React, { Component } from "react";
import Images from "./images";
class App extends Component {
state = {
images: [
"https://loremflickr.com/320/240?random=1",
"https://loremflickr.com/320/240?random=2",
"https://loremflickr.com/320/240?random=3"
@h09shais
h09shais / App.config
Created August 17, 2018 16:31
C# Write custom event log entry
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<!-- supported items-->
</startup>
<system.diagnostics>
<sources>
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="EventLog"/>
@h09shais
h09shais / Helper.cs
Created August 23, 2018 10:02
C# Model to XML
private static string CreateXml(object model)
{
var xmlDoc = new XmlDocument();
var xmlSerializer = new XmlSerializer(model.GetType());
using (var xmlStream = new MemoryStream())
{
xmlSerializer.Serialize(xmlStream, model);
xmlStream.Position = 0;
xmlDoc.Load(xmlStream);
return xmlDoc.InnerXml;
@h09shais
h09shais / GetCircularReferences.sql
Created October 30, 2018 11:16
Finding Circular Foreign Key References
-- Source: https://blogs.msdn.microsoft.com/appfabricannounce/2010/07/01/finding-circular-foreign-key-references/
SET NOCOUNT ON
-- WWB: Create a Temp Table Of All Relationship To Improve Overall Performance
CREATE TABLE #TableRelationships (FK_Schema nvarchar(max), FK_Table nvarchar(max),
PK_Schema nvarchar(max), PK_Table nvarchar(max))
-- WWB: Create a List Of All Tables To Check
CREATE TABLE #TableList ([Schema] nvarchar(max), [Table] nvarchar(max))
@h09shais
h09shais / object.js
Created November 7, 2018 12:37
JavaScript: Underscore Array to Object
_.object(
_.map(["One", "Two", "Three"], function(value, key) {
return [value, value];
})
);
@h09shais
h09shais / Index.cs
Created November 8, 2018 09:23
C# Action, Predicate and Func
Action<string> Print = item => Console.WriteLine(item);
// void Print(string item) => Console.WriteLine(item); // To local function
var items = new List<string> { "Apple", "Mango", "Banana" };
items.ForEach(Print);
Predicate<string> Predicate = item => item.Length > 5;
// bool Predicate(string item) => item.Length > 5; // To local function
var result = items.FindAll(Predicate);
result.ForEach(Print);
@h09shais
h09shais / certificate.txt
Last active November 13, 2018 11:21
Generate a private key and a certificate
[1] Generate a private key and a certificate
Ref: https://web.archive.org/web/20120203022122/http://www.silassewell.com/blog/2010/06/03/node-js-https-ssl-server-example/
openssl genrsa -out privatekey.pem 1024
openssl req -new -key privatekey.pem -out certrequest.csr
openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem
[2] Convert PEM to DER
Ref: https://www.sslshopper.com/ssl-converter.html
@h09shais
h09shais / app.js
Created November 10, 2018 06:28
Display PDF by using node express
/*
$ npm init
$ npm install express
$ touch app.js
$ node app.js
*/
var express = require("express"),
fs = require("fs"),
app = express();
@h09shais
h09shais / Note.txt
Created November 12, 2018 09:40
Idea to structure and name files which contain generic classes with the same name
Ref: https://softwareengineering.stackexchange.com/questions/270265/what-is-the-best-way-to-structure-and-name-files-which-contain-generic-classes-w
MyGenericClass<T1>
MyGenericClass<T1, T2>
MyGenericClass<T1, T2, T3>
TO
MyGenericClass`1.cs
MyGenericClass`2.cs
@h09shais
h09shais / Note.txt
Created November 13, 2018 09:54
Headers ain’t headers !
Ref: https://www.troyhunt.com/shhh-dont-let-your-response-headers/
Not all headers are created equal and the way we turn them off within the Microsoft stack differs. Let’s recap on the ones we saw earlier on:
Server: The web server software being run by the site. Typical examples include “Microsoft-IIS/7.5”, “nginx/1.0.11” and “Apache”.
X-Powered-By: The collection (there can be multiple) of application frameworks being run by the site. Typical examples include: “ASP.NET”, “PHP/5.2.17” and “UrlRewriter.NET 2.0.0”.
X-AspNet-Version: Obviously an ASP.NET only header, typical examples include “2.0.50727”, “4.0.30319” and “1.1.4322”.
X-AspNetMvc-Version: Again, you’ll only see this in the ASP.NET stack and typical examples include “3.0”, “2.0” and “1.0”.