Skip to content

Instantly share code, notes, and snippets.

View larroy's full-sized avatar
🎧
In the zone

Pedro Larroy larroy

🎧
In the zone
View GitHub Profile
@larroy
larroy / gpu_count.py
Created October 18, 2019 02:33
List GPUs without cuda drivers
from subprocess import check_output
from collections import namedtuple
import sys
PciDev = namedtuple('PciDev', ['dev', 'devclass', 'vendor', 'devid'])
NV_VENDOR_IDS=set(['1013', '10de'])
def parse_pci(pci):
devices = []
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import mxnet as mx
import mxnet.autograd as ag
from mxnet import nd
from mxnet import gluon
import sys
def main():
@larroy
larroy / wait_ssh_open.py
Last active November 7, 2018 22:14
Wait for ssh to be open in python
def wait_ssh_open(server, port, keep_waiting=None, timeout=None):
""" Wait for network service to appear
@param server: host to connect to (str)
@param port: port (int)
@param timeout: in seconds, if None or 0 wait forever
@return: True of False, if timeout is None may return only True or
throw unhandled network exception
"""
import socket
import errno
@larroy
larroy / UserData
Created September 12, 2017 11:17
A UserData initializer script for AWS instances using Ubuntu or Amazon Linux OS, will setup ephemeral drives as raid and use it for storing docker containers
#!/bin/bash
# To verify if these steps execute correctly, you can check /var/log/cloud-init-output.log in the instances
# Cloud init doesn't log anymore, so we log to user-data log and syslog
# UserData script which installs docker and code deploy agent in AML / Ubuntu
set -e
set -x
exec > >(tee /var/log/user-data.log|logger -t user-data ) 2>&1
@larroy
larroy / run.sh
Created September 6, 2017 13:15 — forked from detunized/run.sh
Mount a read-only folder inside a Docker container with OverlayFS on top
# On the host to run the container
docker run --privileged -i -t -v ~/host-folder-to-mount:/root/folder-ro:ro ubuntu
# Inside the container
# Need to create the upper and work dirs inside a tmpfs.
# Otherwise OverlayFS complains about AUFS folders.
mkdir -p /tmp/overlay && \
mount -t tmpfs tmpfs /tmp/overlay && \
mkdir -p /tmp/overlay/{upper,work} && \
mkdir -p /root/folder && \
class Opts(args: Seq[String]) extends ScallopConf(args) {
val input = opt[String]("input", descr = "input xlsx file", required = false, default = Some("OnCall_form.xlsx"))
val output = opt[String]("output", descr = "output xlsx file", required = false)
val user = opt[String]("user", descr = "user login", required =)
val team = opt[String]("team", descr = "user team", required = true)
val month = opt[Int]("month", descr = "month index starting from 1", required = true)
val year = opt[Int]("year", descr = "year yyyy", required = false,
default = Some(ZonedDateTime.now().getYear))
val pagerDuty = opt[String]("pagerDuty", descr = "pagerduty xml file", required = false)
import java.util.concurrent.{TimeUnit, ArrayBlockingQueue, ThreadPoolExecutor}
import scala.concurrent.ExecutionContext
object ThrottlingExecutionContext {
def apply(poolSize: Int, maxQueued: Int): ExecutionContext = {
val workQueue = new ArrayBlockingQueue[Runnable](maxQueued) {
override def offer(x: Runnable): Boolean = {
put(x)
true
case class A(a: Int, b: Vector[Int], c: Int)
case class B(a: Int, b: Seq[Int], c: Int)
val a = A(...
val b = B(...
val agen = Generic[A]
val bgen = Generic[B]
var observable = Rx.Observable.create(function (observer) {
var source = new Source
while (source.hasNext())
observer.onNext(source.getNext());
});
/************* without having to close over source ************/
@larroy
larroy / selector.ls
Created February 4, 2015 17:26
html select with React + RxJS (livescript)
export mapchooser = (domToAttach)-->
R = this.React
observable = this.Rx.Observable.create((observer)->
MapChooser = R.create-class do
loadMaps: ->
$.getJSON(
"maps",
$.proxy((data) !->
response = $.parseJSON(data)
@setState(maps: response)