Skip to content

Instantly share code, notes, and snippets.

@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++) {
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 / 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);
@alaingilbert
alaingilbert / vessel.sh
Last active August 29, 2015 14:10
vessel.sh
# Solution by Alain Gilbert
# http://www.vessel.com/careers
while grep "eval(" apply.rb > /dev/null; do
sed "s/eval/puts/g" apply.rb > 'tmp.rb';
ruby tmp.rb > 'apply.rb';
done
cat apply.rb
import re
import sublime
import sublime_plugin
import SublimeREPL.sublimerepl
import SublimeREPL.text_transfer
class RefreshNamespacesInReplCommand(SublimeREPL.text_transfer.ReplTransferCurrent):
def run(self, edit):
ns = re.sub("ns\s*", "", self.view.substr(self.view.find("ns\s*\S+",0)))
text = "(require '%s :reload)" % ns
// Key bindings user:
{ "keys": ["alt+super+r"], "command": "refresh_namespaces_in_repl"},
@alaingilbert
alaingilbert / challenge.sh
Created April 11, 2017 05:33
Rainforestqa challenge
# Solution by Alain Gilbert
# http://letsrevolutionizetesting.com/challenge
curl -s http://letsrevolutionizetesting.com/challenge.json > tmp.json
while grep --quiet "follow" tmp.json; do
sed "s/challenge/challenge.json/g" tmp.json > tmp1.json
curl -s $(cat tmp1.json | jq -r '.follow') > tmp.json
done
cat tmp.json | jq -r '.message'
rm tmp.json tmp1.json
@alaingilbert
alaingilbert / index.html
Last active May 5, 2021 12:48
testing async/await in js
<script>
async function run() {
let res = 0;
for (let i = 0; i < 3; i++) {
const response = await fetch('https://jsonplaceholder.typicode.com/todos/1');
const json = await response.json();
res += json.id;
}
console.log(res);
}
@alaingilbert
alaingilbert / main.go
Last active August 10, 2022 01:01
doordash problem
package main
func max(x, y int) int {
if x < y {
return y
}
return x
}
type Node struct {
@alaingilbert
alaingilbert / cargo.toml
Created September 7, 2022 06:17
rust bankers
[package]
name = "rs-bankers"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { version = "1.21.0", features = ["full"] }
tokio-scoped = "0.2.0"