Skip to content

Instantly share code, notes, and snippets.

def xtick_formatter(x, fmt, td, p):
res = None
if x < p[-1][0]:
res = (p[-1][1] + (x - p[-1][0]) * td).strftime(fmt)
else:
#it's reversed
for i in p:
if i[0] <= x:
res = (i[1] + (x - i[0]) * td).strftime(fmt)
break
def play_cycle(self):
if self.busy:
return
self.busy = True
x1 = self.ax[0].get_xlim()
self.ax[0].set_xlim([x1[0] + 1, x1[1] + 1])
#pops two candle lines
import numpy as np
def sig(z):
return 1/(1 + np.exp(-z))
def sig_der(output):
return output*(1 - output)
and_ = 0
if and_:
@avasilkov
avasilkov / time.cpp
Last active December 23, 2015 08:39
long long int getTime(timeval* tp){
gettimeofday(tp, nullptr);
return tp->tv_sec * 1000 + tp->tv_usec / 1000;
}
int main (int argc, char *argv[])
{
struct timeval tp;
long int n = 1000000L;
std::vector<unsigned long int> idx;
@avasilkov
avasilkov / qqq.cpp
Last active January 16, 2016 19:18
struct Sensor{
void sense(CanBeSensed* o){
for(int i = 0; i< 1000000; i++){
for(int j = 0; j< 1000000; j++){
float value = o->getSound(); or o->getSmell();
std::cout<<value<<std::endl;
}
}
}
struct Base{
virtual float getDistance() = 0;
};
struct CanBeSmelled{
Smell smells[10];
Smell getSmell();
};
struct CanBeHeard{
Sound sounds[10];
Sound getSound();
struct CanBeSensed{
uint16 senseMask;
//id for unordered_map inside sensors
static IdInt idCountS;
CanBeSensed(uint16 _senseMask): idS (++idCountS),
senseMask(_senseMask){}
IdInt getIdS() const { return idS; };
void SensorySystem::update() {
loopy(i, subSNumber){
subSystems[i]->sense();
}
if(centralTileSensor.enabled) centralTileSensor.sense(body->GetPosition());
}
void SensorySystem::draw ( NVGcontext* vg ) {
loopy(i, subSNumber){
#ifndef ARCPLACER_H
#define ARCPLACER_H
#include <math.h>
#define loopy(i, n) for(unsigned int i = 0; i < n; i++)
static inline float posMod(float a, float n){
return a - n * floor(a/n);
}
import os
import time
import signal
def timestr(seconds):
if seconds >= 60:
return '%0.0f minutes %0.0f seconds' % (seconds//60, seconds % 60)
else:
return str(int(seconds)) + ' seconds'