Skip to content

Instantly share code, notes, and snippets.

@ahmad2x4
ahmad2x4 / pulumi-app-package.json
Last active May 18, 2020 00:08
Pulumi sample app package.json (partial)
"scripts": {
"start": "node app.js",
"package": "cross-zip ../src deployment.zip "
}
@ahmad2x4
ahmad2x4 / pulumi-app-index-02.ts
Created May 18, 2020 00:06
Pulumi sample app source code part 2
// app.js (continues)
var server = http.createServer(async (req, res) => {
if (req.method === "GET") {
res.writeHead(200, "OK", { "Content-Type": "text/html" });
const result = await try_connect_sql(process.env.CONNECTION_STRING);
res.write(result ? html_connected : html_disconnected);
} else {
res.writeHead(405, "Method Not Allowed", { "Content-Type": "text/plain" });
}
res.end();
@ahmad2x4
ahmad2x4 / pulumi-app-index-01.ts
Last active May 19, 2020 00:47
Pulumi sample app source code
//app.js
const port = process.env.PORT || 3000,
sql = require("mssql"),
http = require("http"),
fs = require("fs"),
html_disconnected = fs.readFileSync("index_disconnected.html"),
html_connected = fs.readFileSync("index_connected.html");
const try_connect_sql = async (connectionString) => {
try {
@ahmad2x4
ahmad2x4 / index.ts
Created May 15, 2020 02:32
Pulumi simple sample index.ts file
import * as aws from "@pulumi/aws";
// Create an AWS resource (S3 Bucket)
const bucket = new aws.s3.Bucket("my-bucket-123");
// Export the name of the bucket
export const bucketName = bucket.id;
public class SortOptionModelBinder : IModelBinder
{
private string[] SEPERATOR = { " " };
private readonly IEnumerable<string> Fields = new []{ "FirstName", "LastName", "Age" };
public bool BindModel(`ttpActionContext actionContext, ModelBindingContext bindingContext)
{
if (bindingContext.ModelType != typeof(SortOption))
{
return false;
public class SortOptionModelBinderTest
{
private HttpActionContext _context;
private ModelBindingContext _bindingContext;
private SortOptionModelBinder _binder;
private IValueProvider _valueProvider;
public SortOptionModelBinderTest()
{
_context = Substitute.For<HttpActionContext>();
@ahmad2x4
ahmad2x4 / sign_model.cs
Last active March 9, 2016 22:51
Signing model properties Wep Api
namespace SampleWebapi
{
internal class SignAttribute : Attribute
{
public string Name { get; set; }
public SignAttribute(string name)
{
Name = name;
}
}
@ahmad2x4
ahmad2x4 / Git aliases
Created January 5, 2016 23:53
git alias
[alias]
co = checkout
ec = config --global -e
up = !git pull --rebase --prune $@ && git submodule update --init --recursive
cob = checkout -b
cm = !git add -A && git commit -m
save = !git add -A && git commit -m 'SAVEPOINT'
wip = !git add -u && git commit -m "WIP"
undo = reset HEAD~1 --mixed
amend = commit -a --amend
@ahmad2x4
ahmad2x4 / gist:90d341b36f94325d596e
Created September 28, 2014 13:51
Blog Automapper Extensions
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Configuration;
using System.Data.Entity;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
@ahmad2x4
ahmad2x4 / Blog_AutomapperExtension10.cs
Created September 28, 2014 12:44
blog Automapper Extension
.Lambda #Lambda1<System.Func`2[AutomapperQuesriableTest.Destination,System.Boolean]>(AutomapperQuesriableTest.Destination $dto)
{
(.New AutomapperQuesriableTest.Source(){
FullName = $dto.Name,
NumberOfYears = $dto.Age
}).FullName == "ahmadreza" && (.New AutomapperQuesriableTest.Source(){
FullName = $dto.Name,
NumberOfYears = $dto.Age
}).NumberOfYears > 10
}