Skip to content

Instantly share code, notes, and snippets.

import pickle
import time
import cvxpy as cp
from cvxpy.lin_ops.lin_utils import ID_COUNTER
# format seconds as hh:mm:ss.sss (approx. ISO 8601 format)
def hhmmss(secs) -> str:
return f"{secs // 3600:02.0f}:{secs // 60:02.0f}:{secs % 60:0.1f}"
@adishavit
adishavit / _arrayToHeap.js
Created February 26, 2017 10:24
Copy JS Int32Array to Emscripten heap for passing as C array
function _arrayToHeap(typedArray){
var numBytes = typedArray.length * typedArray.BYTES_PER_ELEMENT;
var ptr = Module._malloc(numBytes);
var ptr_i32 = ptr >> 2; // divide byte offset by 4 to account for 4-byte int pointer
var heapBytes = Module.HEAP32.subarray(ptr_i32, ptr_i32 + typedArray.length);
heapBytes.set(typedArray);
return heapBytes;
}
@adishavit
adishavit / safe_zip.cpp
Last active September 21, 2016 14:41
Run Time C++ Dependent Type Experiment - zip
#include <vector>
#include <string>
#include <iostream>
#include "optional.hpp"
using nonstd::optional;
class prove_same_size
{
public:
@adishavit
adishavit / proved_non_zero_optional.cpp
Last active September 21, 2016 10:04
Run Time C++ Dependent Type Experiment
#include <string>
#include <iostream>
#include "optional.hpp"
using nonstd::optional; // this is like Maybe. For more complex examples could use variant (discriminated union)
class proved_non_zero_maybe
{
public:
static optional<proved_non_zero_maybe> prove(int v)