View index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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; | |
}; |
View index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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 |
View AWS EC2 UserData to install pgAdmin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
View EC2RunCommandCFN.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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": [ |
View AWS CF Custom Spot lambda - template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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": { |
View AWS CF Custom Spot lambda - part 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
View AWS CF Custom Spot lambda - part 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); |
View nginx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
View IIS Reverse Proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
View DynamoDBJson2Json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function DynamoDBJson2Json(data) { | |
var obj = {}; | |
for(var prop in data) { | |
var key = Object.keys(data[prop])[0]; | |
obj[prop] = data[prop][key]; | |
} | |
return obj; | |
} |
NewerOlder