Skip to content

Instantly share code, notes, and snippets.

View konstantinvlasenko's full-sized avatar
☁️

Konstantin Vlasenko konstantinvlasenko

☁️
View GitHub Profile
@konstantinvlasenko
konstantinvlasenko / index.js
Created January 11, 2020 23:51
Climbing Stairs
/**
* @param {number} n
* @return {number}
*/
let stack = {};
var climbStairs = function(n) {
if (n > 1)
return stack[n] || ( stack[n] = climbStairs(n - 1) + climbStairs(n - 2))
return 1;
};
@konstantinvlasenko
konstantinvlasenko / index.js
Created January 11, 2020 23:14
3Sum JavaScript
/**
* @param {number[]} nums
* @return {number[][]}
*/
var threeSum = function(nums) {
nums.sort((a, b) => { return a - b; });
const result = [];
for (let i = 0; i < (nums.length-2); i ++) {
const a = nums[i];
if (a > 0) return result; // all other numbers to the right are positive as we are working with sorted array
<powershell>
New-Item c:\temp -Type directory
Invoke-WebRequest https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v3.1/windows/pgadmin4-3.1-x86.exe -OutFile c:\temp\pgadmin4-3.1-x86.exe
Start-Process C:\temp\pgadmin4-3.1-x86.exe -ArgumentList '/silent'
</powershell>
@konstantinvlasenko
konstantinvlasenko / EC2RunCommandCFN.json
Created November 1, 2016 03:42
Creates 2 lambdas (RUN and RESULT) to execute and receive results of EC2 Run Command
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Example of using AWS Lambda to run EC2 Command",
"Resources": {
"ROLE": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
@konstantinvlasenko
konstantinvlasenko / AWS CF Custom Spot lambda - template
Created February 17, 2016 04:38
AWS CloudFormation Custom Resource - Spot (template)
{
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"DC": {
"Type": "Custom::SPOT",
"Properties": {
"ServiceToken": "arn:aws:lambda:us-east-1:637921189560:function:cf_spot",
"params": {
"SpotPrice": "0.5",
"LaunchSpecification": {
@konstantinvlasenko
konstantinvlasenko / AWS CF Custom Spot lambda - part 2
Created February 17, 2016 04:36
AWS CloudFormation Custom Resource - Spot (Part 2 - lambda response on instance created)
var AWS = require('aws-sdk');
var https = require('https');
var url = require('url');
AWS.config.apiVersions = {
ec2: '2015-10-01'
};
var ec2 = new AWS.EC2();
@konstantinvlasenko
konstantinvlasenko / AWS CF Custom Spot lambda - part 1
Last active February 17, 2016 04:35
AWS CloudFormation Custom Resource - Spot (Part 1 - lambda creator)
var AWS = require('aws-sdk');
var https = require('https');
var url = require('url');
AWS.config.apiVersions = {
ec2: '2015-10-01'
};
exports.handler = function(event, context) {
var ec2 = new AWS.EC2({ region: event.ResourceProperties.Region });
@konstantinvlasenko
konstantinvlasenko / nginx
Created December 16, 2015 01:34 — forked from vdel26/nginx
Openresty init.d script
#!/bin/sh
#
# chkconfig: 2345 55 25
# Description: Nginx init.d script, put in /etc/init.d, chmod +x /etc/init.d/nginx
# For Debian, run: update-rc.d -f nginx defaults
# For CentOS, run: chkconfig --add nginx
#
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
Invoke-WebRequest 'http://download.microsoft.com/download/C/F/F/CFF3A0B8-99D4-41A2-AE1A-496C08BEB904/WebPlatformInstaller_amd64_en-US.msi' -OutFile "$($env:TEMP)/WebPlatformInstaller_amd64_en-US.msi"
Start-Process "$($env:TEMP)/WebPlatformInstaller_amd64_en-US.msi" '/qn' -PassThru | Wait-Process
cd 'C:/Program Files/Microsoft/Web Platform Installer'; .\WebpiCmd.exe /Install /Products:'UrlRewrite2,ARRv3_0' /AcceptEULA
function New-Farm($name, $accessName, $port)
{
Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter 'webFarms' -name . -value @{name=$name}
Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "/webFarms/webFarm[@name='$name']" -name . -value @{address='127.0.0.1'}
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "/webFarms/webFarm[@name='$name']/server[@address='127.0.0.1']" -name applicationRequestRouting -value @{httpPort=$port}
Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter 'system.webServer/rewrite/
@konstantinvlasenko
konstantinvlasenko / DynamoDBJson2Json
Created December 10, 2013 19:45
convert DynamoDb JSON to regular JSON javascript objects
function DynamoDBJson2Json(data) {
var obj = {};
for(var prop in data) {
var key = Object.keys(data[prop])[0];
obj[prop] = data[prop][key];
}
return obj;
}