Skip to content

Instantly share code, notes, and snippets.

View kyrcha's full-sized avatar

Kyriakos Chatzidimitriou kyrcha

View GitHub Profile
@kyrcha
kyrcha / confirm-ml.py
Last active April 11, 2020 13:29
Confirm your Anaconda ML environment
# Idea from: https://machinelearningmastery.com/setup-python-environment-machine-learning-deep-learning-anaconda/
# scipy
import scipy
print('scipy: %s' % scipy.__version__)
# numpy
import numpy
print('numpy: %s' % numpy.__version__)
# matplotlib
import matplotlib
@kyrcha
kyrcha / README.md
Created June 10, 2020 08:49
Update outdated global npm packages
  1. Check which global packages are outdated with:

npm outdated -g

For example:

  1. Update the pacakges:
@kyrcha
kyrcha / count.sh
Created June 16, 2020 16:22
Calculating lines of code for my React+Node projects with cloc
#!/bin/sh
cloc --fullpath --not-match-d='(node_modules|build|static|coverage|__tests__|tests)' --exclude-list-file=notcount .
@kyrcha
kyrcha / running-average-redis-python.py
Last active July 7, 2020 06:42
Calculate the running average and standard deviation using redis transactions (pipelines in python-redis) and multiple python threads. You can quickly test it by installing a dockerized redis.
from multiprocessing import Pool
import redis
import math
import json
from random import seed
from random import gauss
# Atomic operations
def sum(x):
r = redis.Redis(host='localhost', port=6379, db=0)
@kyrcha
kyrcha / mongodb-dump-and-restore.md
Last active March 11, 2021 10:19
Bring a mongodb database from a cloud atlas cluster, locally, using two commands

Let's assume the database is named "production" in your mongodb atlas cluster. First we do a dump:

mongodump --uri="mongodb+srv://<username>:<password>@<subdomain>.mongodb.net/production" --archive="mongodump-production"

Make sure you fill in the correct:

  • username
  • password
  • subdomain
@kyrcha
kyrcha / remove-sites-enabled-nginx.md
Created March 12, 2021 12:34
Remove website from sites-enabled in nginx
  1. cd /etc/nginx/sites-enabled
  2. ls for checking
  3. sudo rm site-to-be-removed
  4. sudo nginx -t, and if OK
  5. sudo service nginx reload
@kyrcha
kyrcha / pandas-to-tensor.py
Created July 16, 2019 17:02
Converting a pandas dataframe with each row being a vector image to a 4D tensor for CNN use in Keras
# Transforming a 60000x784 dataframe to a 60000x28x28x1 4D tensor for Keras modelling
train_img = X_train.values.reshape(X_train.shape[0], 28, 28, 1)
@kyrcha
kyrcha / websites.controller.ts
Created March 31, 2020 12:15
Really simple example of a website builder with NestJS, 11ty and nginx - websites.controller.ts
import { Controller, Post, Body, Get, UseInterceptors, UploadedFile } from '@nestjs/common';
import { CreateWebsiteDto } from './dto/create-website.dto';
import { FileInterceptor } from '@nestjs/platform-express';
import {existsSync, mkdirSync, writeFileSync} from 'fs';
import { randomBytes } from 'crypto';
import { join } from 'path';
import { copySync } from 'fs-extra';
import { exec, pwd } from 'shelljs';
import * as rimraf from 'rimraf';
@kyrcha
kyrcha / LINUX.md
Last active October 25, 2021 07:50
Basic linux commands without ads

Linux commands

Notes:

  • change or anything with <...> with the values you want

Users

Create a user

Use:

@kyrcha
kyrcha / local.md
Created July 29, 2022 08:44
Finding all local dependencies as a tree for a python file

Using the library importlab and grep on a shell prompt from the project's root folder:

importlab --tree path/to/file.py | grep -E '^\s+[^::]*py$'