Skip to content

Instantly share code, notes, and snippets.

@martin-denizet
martin-denizet / self-driving-car-testing.rb
Created June 11, 2018 12:50
Codingame: Self-driving car testing
## Detailed beginner solution ##
# Number of road patterns
n = gets.to_i
steering_commands = gets.chomp.split(';')
# Car position on the road first position is 1 and not 0
# That's why we need to substract 1
car_pos=steering_commands.shift.to_i-1
# We will build an array of all the steering instructions to apply
steering_per_turn=[]
steering_commands.each do |command_block|
@martin-denizet
martin-denizet / there-is-no-spoon-episode-1.py
Last active June 11, 2018 11:41
Codingame: The is no Spoon - Episode 1
import sys
import math
grid=[]
class Node(object):
def __init__(self,x,y):
self.x=x
self.y=y
def right_n(self):
right=list(filter(lambda n: n.x>self.x and n.y==self.y, grid))
# n: the number of temperatures to analyse
read n
closest_to_zero=9999
read temperatures
for t in $temperatures; do
# t: a temperature expressed as an integer ranging from -273 to 5526
echo "New temperature: ${t} closest to 0 so far: ${closest_to_zero}" >&2
# Compare absolute values
if [[ "${t#-}" -lt "${closest_to_zero#-}" ]]; then
closest_to_zero=$t
@martin-denizet
martin-denizet / codingame-horse-racing-duals.sh
Last active June 7, 2018 15:11
Identifies the closest strength between 2 horses. Codingame puzzle at https://www.codingame.com/ide/puzzle/horse-racing-duals
read N
# An array of horses
declare -a horses
closest_strength=10000000
# Initialize last to -1 because it's an invalid value
last=-1
for (( i=0; i<N; i++ )); do
read horse
# We set the value as the key because it will be sorted automatically
horses[$horse]=1
# Redirection of port 80 to port 443
<virtualhost *:80>
ServerName redmine.domain.com
KeepAlive Off
RewriteEngine On
#RewriteCond %{HTTP_HOST} ^[^\./]+\.[^\./]+$
RewriteRule ^/(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
#!/bin/sh
# XenServer autostart script
# Use at your own risks
# Do not use with VMs using HA.
# Instructions:
# 1. Put this script in /root
# 2. Give execution permission: "chmod +x /root/xs_autostart.sh"
# 3. Add "@reboot /root/xs_autostart.sh" in root's crontab
# 4. Add the "autostart" to VM needing it
# 5. Add "autostart" in the descriptions of vApps needing it