Skip to content

Instantly share code, notes, and snippets.

View ialhashim's full-sized avatar

Ibraheem Alhashim ialhashim

View GitHub Profile
@ialhashim
ialhashim / readme.md
Last active April 2, 2024 11:17
Reverse port forwarding via an AWS instance

If you want to connect to a local workstation behind a firewall you can do that by bouncing traffic off of an AWS instance.

An example would be accessing a Jupyter Lab from the outside world to a machine with no static IP or behind a firewall.

The steps are:

  1. Create a paid AWS Ubuntu instance and save the '.pem' file.
  2. Make sure the AWS instance's Security Rules allows traffic in.
  3. Test that you can connect to this instance from the outside world (e.g. python3 -m http.server or jupyter lab --ip=*) then visit the instance using its public IP.
  4. (optionally) Enable password login in /etc/ssh/sshd_config by setting PasswordAuthentication yes and sudo passwd $USER.
  5. Enable GatewayPorts yes and restart sshd. E.g. sudo nano /etc/ssh/sshd_config then sudo systemctl restart ssh.service.
@ialhashim
ialhashim / fitting3D.cpp
Created November 14, 2014 23:17
Fitting 3D points to a plane or a line
template<class Vector3>
std::pair<Vector3, Vector3> best_plane_from_points(const std::vector<Vector3> & c)
{
// copy coordinates to matrix in Eigen format
size_t num_atoms = c.size();
Eigen::Matrix< Vector3::Scalar, Eigen::Dynamic, Eigen::Dynamic > coord(3, num_atoms);
for (size_t i = 0; i < num_atoms; ++i) coord.col(i) = c[i];
// calculate centroid
Vector3 centroid(coord.row(0).mean(), coord.row(1).mean(), coord.row(2).mean());
@ialhashim
ialhashim / DBSCAN.hpp
Last active March 24, 2024 22:04
Portable Clustering Algorithms in C++ (DBSCAN) and (Mean-Shift) and (k-medoids)
#pragma once
// Code adapted from https://github.com/propanoid/DBSCAN
#include <vector>
#include <algorithm>
#include <omp.h>
// Any basic vector/matrix library should also work
#include <Eigen/Core>
@ialhashim
ialhashim / fill_depth_colorization.py
Last active February 6, 2024 03:27
Python implementation of depth filling from NYU Depth v2 toolbox
# Original Matlab code https://cs.nyu.edu/~silberman/datasets/nyu_depth_v2.html
#
#
# Python port of depth filling code from NYU toolbox
# Speed needs to be improved
#
# Uses 'pypardiso' solver
#
import scipy
import skimage
==============================
Expression: (id=\d)(.+?)(")
==============================
Python script to download:
import os.path
@ialhashim
ialhashim / firebase_storage_web.dart
Created January 8, 2020 09:48
Flutter + Firebase storage on the web, work around
// Note this is just a workaround until the offical support of web
// We would need to add these as well
//// ignore_for_file: avoid_web_libraries_in_flutter
//import 'dart:html';
//import 'package:mime/mime.dart';
//import 'package:firebase/firebase.dart' as fb;
// Some upload button is pressed
onPressed: () async {
@ialhashim
ialhashim / screencapture.cpp
Last active October 28, 2023 20:41
Portable screen capture using C++ under Windows 10 (or 8)
#include "screengrab.h"
void capture()
{
CComPtr<ID3D11Device> pDevice;
CComPtr<IDXGIOutputDuplication> pDeskDupl;
//(...)create devices and duplication interface etc here..
DXGI_OUTDUPL_DESC OutputDuplDesc;
@ialhashim
ialhashim / drawPointCloud.py
Last active July 18, 2023 20:56
Quick python script to draw a dynamic point cloud with changing colors and positions (e.g. RGBD frames)
from OpenGL import GL, GLU
from OpenGL.arrays import vbo
# Prepare point cloud once
def makeCloud(self):
width, height = self.rgb.shape[1], self.rgb.shape[0]
# ...
# Compute 3D positions from depth
# ...
@ialhashim
ialhashim / powercrust.h
Created December 26, 2014 03:18
Portable Powercrust in C++
// Portable version of powercrust, adapted from https://github.com/timhutton/vtkpowercrust
/*===================================================================================================
vtkPowerCrustSurfaceReconstruction algorithm reconstructs surfaces from unorganized point data.
Copyright (C) 2014 Arash Akbarinia, Tim Hutton, Bruce Lamond Dieter Pfeffer, Oliver Moss
====================================================================================================*/
/*
#include "CellArray.h"
@ialhashim
ialhashim / split_predict_batches.py
Created January 15, 2023 07:30
Split images into square patches
def split_to_batches(img, trained_size=512):
img = skimage.img_as_float32(img)
direction = 'landscape'
if img.shape[0] > img.shape[1]: direction = 'portrait'
# resize into 512x[width|height]
width, height = img.shape[1], img.shape[0]
if direction == 'landscape':
new_height = trained_size
new_width = int(new_height * (width / height))