Skip to content

Instantly share code, notes, and snippets.

@Kalki5
Kalki5 / add_policy.py
Created March 19, 2019 06:22
Add own policy to a lambda function
import boto3
lamba_client = boto3.client('lambda', region_name='REGION_NAME')
lamba_client.add_permission(
FunctionName='create_lab',
StatementId='AWSEventsRule',
Action='lambda:InvokeFunction',
Principal='events.amazonaws.com',
SourceArn='arn:aws:events:REGION_NAME:ACCOUNT_NUMBER:rule/*',
@Kalki5
Kalki5 / script.sh
Created February 14, 2019 09:33
docker
# Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose --version
vim docker-compose.yml
version: "3"
services:
@Kalki5
Kalki5 / install.sh
Last active January 5, 2019 14:31
Install Guacamole with JWT Extension
# Install Docker
sudo curl -sS https://get.docker.com/ | sh
sudo usermod -aG docker ${USER}
docker run --name guacd -d -p 4822:4822 guacamole/guacd
# Install Tomcat8
apt-get update
apt-get -y install build-essential tomcat8 wget
@Kalki5
Kalki5 / script.ps1
Created October 29, 2018 13:58
Enable WinRM for Inspec in Windows server 2016 using powershell script in AWS EC2 userdata
<powershell>
winrm quickconfig -q
winrm set winrm/config/client/auth '@{Basic="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/client '@{AllowUnencrypted="true"}'
$hostname = (Invoke-WebRequest 'http://169.254.169.254/latest/meta-data/public-hostname').Content
winrm set winrm/config/client '@{TrustedHosts="' ${hostname} '"}'
</powershell>
@Kalki5
Kalki5 / installOpenSSH.ps1
Created August 16, 2018 15:52
OpenSSH on Windows server 2016 - Powershell script
Set-Location -Path 'C:\Program Files'
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri 'https://github.com/PowerShell/Win32-OpenSSH/releases/download/v7.7.2.0p1-Beta/OpenSSH-Win64.zip' -OutFile openssh.zip
Expand-Archive 'openssh.zip' -DestinationPath 'C:\Program Files\'
$oldpath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path
$newpath = "$oldpath;C:\Program Files\OpenSSH-Win64"
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath
@Kalki5
Kalki5 / calculate_costs.py
Created March 28, 2018 17:28
Calculate costs estimated by AWS cost explorer API
import boto3
session = boto3.Session()
for profile in session.available_profiles:
try:
client = boto3.Session(profile_name=profile).client('ce')
amount = client.get_cost_and_usage(
TimePeriod={'Start': '2018-03-01', 'End': '2018-03-28' },
Granularity='MONTHLY',
@Kalki5
Kalki5 / embedded-file-viewer.md
Created March 19, 2018 05:22 — forked from tzmartin/embedded-file-viewer.md
Embedded File Viewer: Google Drive, OneDrive

Office Web Apps Viewer

('.ppt' '.pptx' '.doc', '.docx', '.xls', '.xlsx')

http://view.officeapps.live.com/op/view.aspx?src=[OFFICE_FILE_URL]

<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=[OFFICE_FILE_URL]' width='px' height='px' frameborder='0'>
</iframe>

OneDrive Embed Links

@Kalki5
Kalki5 / Enable MySQL Remote Login
Created March 8, 2018 13:53
Enable MySQL Remote Login
sudo su
mysql -uroot -ppassword
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password';
exit;
vim /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address = 0.0.0.0
service mysql restart
@Kalki5
Kalki5 / common.conf
Last active April 26, 2018 05:48
Deploy django 2.0.2 (REST app) on Ubuntu 16.04 with apache 2.4, python 3.6 and mod_wsgi
NameVirtualHost *:80
<VirtualHost *:80>
ServerName job.api.XXXXX.XXX
ServerAlias job
ServerAdmin webmaster@localhost
SetEnv DJANGO_SETTINGS_MODULE job_service.settings.production
<Directory /var/www/html/job.service/job_service>
@Kalki5
Kalki5 / next.json-generator.com
Created March 3, 2018 07:16
Dummy json generator
[
{
'repeat(30, 60)': {
"model": "common.job",
"pk": '{{index()}}',
"fields": {
"title": '{{lorem(1, "words")}}',
"company_id": '{{integer()}}',
"level": '{{random("beginner", "intermediate", "expert")}}',
"location": "{{country()}}",