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 express = require('express') | |
var bodyparser = require('body-parser') | |
var sp = require('serialport') | |
var SerialPort = sp.SerialPort | |
var app = express() | |
app.all('/', function(req, res, next) { | |
res.header("Access-Control-Allow-Origin", "*"); | |
res.header("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,OPTIONS"); | |
res.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With, Session"); | |
next(); |
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
// Parses a url query (key=val&key_2=val_2&key_3=val_3) into a map | |
std::map<std::string, std::string> query_to_map(const std::string query) { | |
std::map<std::string, std::string> res; | |
std::ostringstream curr_key; | |
std::ostringstream curr_val; | |
bool in_key = true; | |
for(const auto& s : query) { | |
if(s == '=') { | |
in_key = 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
int n_tiles; //number of tiles | |
int grid_x = 0; | |
int grid_y = 0; | |
for(int n = 1; n < ceil(sqrt(n_tiles) + 1); n++) { | |
if(n_tiles%n == 0) { | |
grid_y = n; | |
grid_x = n_tiles/n; | |
} | |
} |
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 unpool(x, repeat=False): | |
s = x.shape | |
if repeat: | |
r = 1 | |
else: | |
r = 0 | |
kernel_x = np.tile([1, r] + [0,0] * (s[1]), s[1])[:s[1]*s[1]*2].reshape(s[1], (s[1]*2)) | |
kernel_y = np.tile([1, r] + [0,0] * (s[0]), s[0])[:s[0]*s[0]*2].reshape(s[0], s[0]*2) | |
return np.matmul(np.matmul(x, kernel_x).transpose(), kernel_y).transpose() |
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
const string allowed_ext[] = {"jpg", "png", "gif", "jpeg"}; //File types detected by the search | |
vector<ofFile> files; | |
void ofApp::scan_dir(ofDirectory dir){ | |
ofDirectory new_dir; | |
int size = dir.listDir(); | |
for (int i = 0; i < size; i++){ | |
if (dir.getFile(i).isDirectory()){ | |
new_dir = ofDirectory(dir.getFile(i).getAbsolutePath()); | |
new_dir.listDir(); |
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
//-------------------------------------------------------------- | |
void ofApp::setup() { | |
uarm.setup("/dev/tty.usbserial-A600CRMU", 9600); | |
} | |
//-------------------------------------------------------------- | |
// x, y, z in cylindrical coordinates, handRot in degrees | |
void ofApp::setArmTo(int x, int y, int z, int handRot, bool gripper) { | |
// UArm expects 1 for an open gripper and 2 for a closed gripper | |
gripper = (int)gripper + 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
class OptimisticDict(dict): | |
def __init__(self, factory_func): | |
self.factory_func = factory_func | |
super(OptimisticDict, self).__init__() | |
def __missing__(self, key): | |
self[key] = self.factory_func(key) | |
return self.factory_func(key) |
NewerOlder