This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gpu_count() -> int: | |
"""Get number of gpus.""" | |
import ctypes | |
try: | |
cuda = ctypes.CDLL("libcuda.so") | |
except OSError: | |
logging.exception("Loading libcuda") | |
return 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 && \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var observable = Rx.Observable.create(function (observer) { | |
var source = new Source | |
while (source.hasNext()) | |
observer.onNext(source.getNext()); | |
}); | |
/************* without having to close over source ************/ |
NewerOlder