Skip to content

Instantly share code, notes, and snippets.

View tomahim's full-sized avatar

Thomas Himblot tomahim

View GitHub Profile
@tomahim
tomahim / .eb-config.sh
Last active September 9, 2022 15:49
Bash script to create an AWS credential file
#!/usr/bin/env bash
set -x
set -e
{
AWS_CONFIG_FILE=~/.aws/config
mkdir ~/.aws
touch $AWS_CONFIG_FILE
chmod 600 $AWS_CONFIG_FILE
@tomahim
tomahim / test_dumbclass.py
Created August 30, 2018 10:01
Dumb python unit test
import unittest
class TestDumbClass(unittest.TestCase):
def setUp(self):
pass
def test_useless_assert(self):
self.assertEqual('1', '1')
@tomahim
tomahim / application.py
Last active August 25, 2018 14:26
Hello world Flask application
from flask import Flask
application = Flask(__name__)
@application.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == '__main__':
application.run(debug=True, port=8080)
@tomahim
tomahim / data_augmentation.py
Last active January 20, 2022 08:26
Data augmentation in few lines with skimage
import os
import random
from scipy import ndarray
# image processing library
import skimage as sk
from skimage import transform
from skimage import util
from skimage import io
@tomahim
tomahim / save_file_skimage.py
Created March 3, 2018 17:40
Write file to the disk with skimage
# define a name for our new file
new_file_path = '%s/augmented_image_%s.jpg' % (folder_path, num_generated_files)
# write image to the disk
sk.io.imsave(new_file_path, transformed_image)
@tomahim
tomahim / random-skimage-transformation.py
Last active March 4, 2018 21:33
Apply random transformations
# dictionary of the transformations functions we defined earlier
available_transformations = {
'rotate': random_rotation,
'noise': random_noise,
'horizontal_flip': horizontal_flip
}
# random num of transformations to apply
num_transformations_to_apply = random.randint(1, len(available_transformations))
@tomahim
tomahim / skimage_transformation.py
Last active March 3, 2018 17:22
Simple image transformation with scikit-image
import random
from scipy import ndarray
import skimage as sk
from skimage import transform
from skimage import util
def random_rotation(image_array: ndarray):
# pick a random degree of rotation between 25% on the left and 25% on the right
random_degree = random.uniform(-25, 25)
return sk.transform.rotate(image_array, random_degree)
@tomahim
tomahim / pick_random_files.py
Last active November 2, 2020 18:31
Pick random files from a folder and read them
import random
import os
# our folder path containing some images
folder_path = 'images/cats'
# the number of file to generate
num_files_desired = 1000
# loop on all files of the folder and build a list of files paths
images = [os.path.join(folder_path, f) for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
@tomahim
tomahim / ngb-date-moment-adaptater.ts
Created January 10, 2018 10:20
NgbDate momentJS adapter for Bootstrap datepicker
import { Injectable } from '@angular/core';
import { NgbDateAdapter, NgbDateStruct } from '@ng-bootstrap/ng-bootstrap';
import * as moment from 'moment';
@Injectable()
export class NgbDateMomentAdapter extends NgbDateAdapter<moment.Moment> {
fromModel(date: moment.Moment): NgbDateStruct {
if (!date) {
return null;
@tomahim
tomahim / controllers.js
Last active December 25, 2015 12:39
Implement touch events like tap and doubletap on the same element with Angular.js, Hammer.js and the plugin jQuery/Hammer. This gist avoid to fire a tap event when we try to fire a double tap event on an element. Note : We will not use tap event, but we will consider a tap event as a click. I think it's a quite good solution since tap event is v…
app.controller("AppCtrl", function($scope){
var count = 0;
var timeout;
/*
* This function count each click. At the first click
* it create a timeout of 300 ms.
* If a second click is fire on this interval it will
* execute what we want on "double tap".