Skip to content

Instantly share code, notes, and snippets.

View flavienbwk's full-sized avatar

Flavien Berwick flavienbwk

  • Montréal, Canada
  • 15:08 (UTC -04:00)
View GitHub Profile
@flavienbwk
flavienbwk / myChef.sh
Created May 29, 2018 14:28
Automatically creates a fresh Wordpress install.
#!/bin/bash
# Variables
log_path="error.log"
log_path_custom="install.log"
master_domain="mywebchef.org"
domain="wp.mywebchef.org"
ip_address="xxx.xxx.xxx.xxx"
wp_email="myemailaddress@test.fr"
@flavienbwk
flavienbwk / all_subsets_of_a_set.py
Last active January 24, 2019 15:05
Coding interview problem : prints all the subsets of a list of numbers (integers).
# This is the kind of software engineering interview algorithm you may have to do at Facebook.
# You must print all the subsets of a given set.
#
# If the input is [1, 2, 3], you will have to print :
#
# 1, 2, 3,
# 1, 2,
# 1, 3,
# 1,
# 2, 3,
@flavienbwk
flavienbwk / intersections_between_arrays.py
Last active January 24, 2019 15:05
Coding interview problem : returns the same numbers present in each given list.
# Find the numbers that appear in all arrays.
# Return them as a list.
#
# Input :
# [2, 6, 9, 11, 13, 17]
# [3, 6, 7, 10, 13, 18]
# [4, 5, 6, 9, 11, 13]
#
# Output must be :
# [6, 13]
@flavienbwk
flavienbwk / longest_consecutive_sequence.py
Created January 24, 2019 16:53
Coding interview problem : find the longest consecutive sequence in a sequence.
# You have to return the longest consecutive sequence of numbers in an array.
# If the input is [2, 1, 6, 9, 4, 3], the output must be [1, 2, 3, 4]
# O(n)
def longestSequence(sequence):
hashtable = {}
longest = []
for i in range(0, len(sequence)):
hashtable[sequence[i]] = True
for number in hashtable:
@flavienbwk
flavienbwk / king_and_queen.py
Created January 24, 2019 17:16
Coding interview problem : king and queen on a chessboard.
# Given a chessboard, how would you find whether the king is threatened by the queen ?
#
# King position : kx, ky
# Queen position : qx, qy
#
# There's only a queen and a king on the chessboard.
# Output is True or False.
def endangeredKing(k_pos, q_pos):
if (q_pos[0] - k_pos[0] == 0):
@flavienbwk
flavienbwk / move_zeros.py
Created January 24, 2019 21:50
Coding interview problem : move all zeros present in the array to the end, and return the SAME array.
# Move all zeros present in the array to the end, and return the SAME array.
#
# I: [0, 1, 2, 0, 3, 0]
# O: [1, 2, 3, 0, 0, 0]
#
# No empty array.
# No negative numbers.
def shiftZeros(array):
i = 0
@flavienbwk
flavienbwk / Max_Dissolved_Oxigen.c
Created May 15, 2019 22:02 — forked from erikyo/Max_Dissolved_Oxigen.c
Max Dissolved Oxigen Saturation over a range of user-specified values for water temperature, barometric pressure, and salinity or specific conductance.
// --------- Max Dissolved Oxigen Saturation ------------//
//
// Equation for the Henry coefficient as a function of temperature and salinity is used to calculate values
// for unit standard atmospheric concentrations (USAC) in freshwater and seawater in equilibrium with air at a total pressure
// of 1 atmosphere. It is estimated that the possible error in the new USAC values is no greater than $\pm 0.1%$ and probably less.
// Tables and equations are presented for obtaining accurate USAC values in the ranges $0^\circ < t < 40^\cir C and 0 < S < 40$.
// Simple procedures are given for calculating standard atmospheric concentrations at pressures different from 1 atm.
//
// Reference https://water.usgs.gov/software/DOTABLES/
// Dissolved oxygen (DO) solubility over a range of user-specified values for
@flavienbwk
flavienbwk / rsatool.py
Last active September 1, 2019 16:25
Generates a private key from the modulus, prime1 and prime2 parameters.
#!/usr/bin/env python2
# Usage : python rsatool.py -n <decimal_modulus> -p <decimal_prime1> -q <decimal_prime2> -e 65537 -v DER -o private.key
import base64, fractions, optparse, random
try:
import gmpy
except ImportError as e:
try:
import gmpy2 as gmpy
@flavienbwk
flavienbwk / .travis.yml
Created October 31, 2019 21:24
Travis-CI example for docker-compose
sudo: required
services:
- docker
env:
- DOCKER_COMPOSE_VERSION=1.23.2
before_install:
- sudo rm /usr/local/bin/docker-compose
@flavienbwk
flavienbwk / MIC-COMMANDS.md
Created January 27, 2021 23:03
Enable or disable your microphone loopback sound on Ubuntu.

Enable mic loopback

pactl load-module module-loopback latency_msec=1

Disable mic loopback

pactl unload-module module-loopback