Skip to content

Instantly share code, notes, and snippets.

View nataz77's full-sized avatar
👻
Telling computers what to do

Simone Natalini nataz77

👻
Telling computers what to do
View GitHub Profile
@nataz77
nataz77 / CronBackup.sh
Last active November 6, 2018 13:58
Backup on Linux systems
#!/bin/sh
DIR=date+%m%d%y
DEST=/db_backups/$DIR
mkdir $DEST
for fn in cat filenames.txt;
do mongodump -h localhost:27017 -d $fn -u $user -p $pwd -o $DEST --ssl
done
@nataz77
nataz77 / DuplicateQuery.js
Created November 6, 2018 13:59
MongoDB Duplicates query
db.getCollection('CollectionName').aggregate(
{"$group" : { "_id": "$ItemKey", "count": { "$sum": 1 } } },
{"$match": {"_id" :{ "$ne" : null } , "count" : {"$gt": 1} } },
{"$project": {"name" : "$_id", "_id" : 0}}
)
@nataz77
nataz77 / cleanup.sh
Created November 6, 2018 14:01 — forked from superseb/cleanup.sh
Cleanup host added as custom to Rancher 2.0
#!/bin/sh
docker rm -f $(docker ps -qa)
docker volume rm $(docker volume ls -q)
cleanupdirs="/var/lib/etcd /etc/kubernetes /etc/cni /opt/cni /var/lib/cni /var/run/calico /opt/rke"
for dir in $cleanupdirs; do
echo "Removing $dir"
rm -rf $dir
done
@nataz77
nataz77 / mongodb-objectid.js
Created January 11, 2019 16:04 — forked from chrisveness/mongodb-objectid.js
Generates a MongoDB-style ObjectId in Node.js
/**
* Generates a MongoDB-style ObjectId in Node.js. Uses nanosecond timestamp in place of counter;
* should be impossible for same process to generate multiple objectId in same nanosecond? (clock
* drift can result in an *extremely* remote possibility of id conflicts).
*
* @returns {string} Id in same format as MongoDB ObjectId.
*/
function objectId() {
const os = require('os');
const crypto = require('crypto');
@nataz77
nataz77 / extended-cleanup-rancher2.sh
Last active October 26, 2020 11:36 — forked from superseb/extended-cleanup-rancher2.sh
Extended Rancher 2 cleanup
#!/bin/sh
# Backup your data
# Use at your own risk
# Usage ./extended-cleanup-rancher2.sh
# Include clearing all iptables: ./extended-cleanup-rancher2.sh flush
docker rm -f $(docker ps -qa)
docker rmi -f $(docker images -q)
docker volume rm $(docker volume ls -q)
for mount in $(mount | grep tmpfs | grep '/var/lib/kubelet' | awk '{ print $3 }') /var/lib/kubelet /var/lib/rancher; do umount $mount; done
cleanupdirs="/etc/ceph /etc/cni /etc/kubernetes /opt/cni /opt/rke /run/secrets/kubernetes.io /run/calico /run/flannel /var/lib/calico /var/lib/etcd /var/lib/cni /var/lib/kubelet /var/lib/rancher/rke/log /var/log/containers /var/log/pods /var/run/calico"
@nataz77
nataz77 / Dockerfile
Created April 2, 2019 14:26
Node.js Dockerfile with Babel
FROM node:alpine
WORKDIR /usr/src/app
COPY ["package.json", "npm-shrinkwrap.json*", "./"]
RUN npm install --silent && mv node_modules ../
COPY . .
RUN npm install --save-dev @babel/core @babel/cli @babel/preset-env
RUN npm run build
EXPOSE 80
CMD ["node", "dist/server.js"]
@nataz77
nataz77 / docker-cleanup.ps1
Created April 12, 2019 10:02
Powershell docker cleanup script to clean all images, containers and volumes before pruning
docker ps -a -q | % { docker stop $_ }
docker ps -a -q | % { docker rm $_ }
docker images --filter "dangling=true" -q --no-trunc | % { docker rmi $_ -f }
docker volume ls -qf dangling=true | % { docker volume rm $_ }
docker system prune -a
@nataz77
nataz77 / mount.sh
Last active July 23, 2019 14:43
GlusterFS Clients mount
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
dpkg -s glusterfs-client &> /dev/null
if [ $? -ne 0 ]
then
echo "GlusterFS is not installed; proceeding to install"
apt update
param (
[switch] $Cache
)
$start_args = if ($Cache) {
'repair', '--cache'
} else {
'modify', '--nocache'
}
get-vssetupinstance -all | Where-Object { $_.DisplayName -eq 'Visual Studio Professional 2019'} | foreach-object {
$args = $start_args + '--installPath', "`"$($_.InstallationPath)`"", '--passive', '--norestart'
Connect-AzureRmAccount
Select-AzureRmSubscription -SubscriptionId "subid"
$webapps = Get-AzureRmWebApp -ResourceGroupName 'rgname'
foreach ($webapp in $webapps) {
$app = Get-AzureRmResource -ResourceId $webapp.Id
$app.Properties.httpsOnly = $true
$app | Set-AzureRmResource -Force