Skip to content

Instantly share code, notes, and snippets.

@alaingilbert
alaingilbert / trello.js
Last active August 29, 2015 14:08
Trello dev challenge
// Solution by Alain Gilbert
// https://trello.com/jobs/developer
var letters = 'acdegilmnoprstuw';
var expected = 956446786872726;
var answer = '';
for (var i = 9; i >= 0; i--) {
var mult = Math.pow(37, i);
var position = Math.floor(expected / mult);
class HistogramProblem(object):
def __init__(self, arr):
self.arr = arr
def water_in_range(self, left, right):
count = 0
minimum = min(self.arr[left], self.arr[right])
for i in range(left+1, right+1):
@alaingilbert
alaingilbert / gist:5152074
Last active August 17, 2023 16:47
Get your current avatar id.
bot.on 'roomChanged', (data) ->
for user in data.users
if user.userid == bot.userId
console.log user.avatarid
break
# Equivalent javascript code.
bot.on('roomChanged', function(data) {
for (i = 0; i < data.users.length; i++) {
@alaingilbert
alaingilbert / main.py
Created November 14, 2012 04:36
Get a pdf on seao.ca
#! /usr/bin/python
# INSTALLATION:
# pip install requests
# pip install beautifulsoup4
from bs4 import BeautifulSoup
import os
import requests
@alaingilbert
alaingilbert / main.py
Created August 22, 2012 01:01
How many squares question...
# http://www.quora.com/Puzzle-and-Trick-Questions/How-many-squares-are-in-this-picture
def get_square_count(length):
squares = 0
nb_nodes = length ** 2
for i in range(nb_nodes):
tmp = i + 1
while tmp % 5 != 0 and tmp + ((tmp - i) * length) < nb_nodes:
tmp += 1
squares += 1
<!doctype html>
<html>
<head>
</head>
<body>
<canvas id="canvas" width="800" height="600"></canvas>
<script type="text/javascript">
var ctx = document.getElementById('canvas').getContext('2d')
@alaingilbert
alaingilbert / index.html
Created May 25, 2012 00:42
Object follow a bezier curve
<!doctype html>
<html>
<head>
</head>
<body>
<canvas id="canvas" width="800" height="600"></canvas>
<script type="text/javascript">
var ctx = document.getElementById('canvas').getContext('2d')
@alaingilbert
alaingilbert / index.html
Created May 13, 2012 15:28
Sprite state
<!doctype html>
<html>
<head>
<style>
label { display: block; width: 70px; float: left; border-right: 1px solid #187215; padding: 5px; }
.box { color: #187215; clear: both; border: 1px solid #187215; margin: 5px; background-color: #e9ffe8; }
.cross { width: 30px; height="30px"; display: block; background-color: #f6fff6; text-align: center; float: left; padding: 5px; }
.ctrl { margin: 20px; }
.left { float: left; }
.clear { clear: both; }
@alaingilbert
alaingilbert / main.py
Created March 11, 2012 06:14
CallTV answer
v = {'A': list('CDFIKEGJLPQHMRSNU'),
'B': list('CEHNUDGMTFJRILKPO'),
'C': list('ABDFIKOEHNU'),
'D': list('ACBFIKOGMS'),
'E': list('ACBHNUGJLP'),
'F': list('AJROKIDCB'),
'G': list('ADMSPLJEB'),
'H': list('ACENUBMR'),
'I': list('ALQOKFDCB'),
'J': list('AFRPLGEB'),
import urllib2, urllib, re, sys
def main():
if not len(sys.argv) > 1:
print "You shall give a genre. example: python band.py house"
return
keyword = sys.argv[1]