Skip to content

Instantly share code, notes, and snippets.

View AlexanderSavochkin's full-sized avatar

Alexander Savochkin AlexanderSavochkin

View GitHub Profile
@AlexanderSavochkin
AlexanderSavochkin / static.cube.opengl.matrices.cpp
Created August 23, 2016 05:52
Model and MVP matrices for static cube (from OpenGL tutorial)
// Model matrix : an identity matrix (model will be at the origin)
glm::mat4 Model = glm::mat4(1.0f);
// Our ModelViewProjection : multiplication of our 3 matrices
glm::mat4 MVP = Projection * View * Model; // Remember, matrix multiplication is the other way around
@AlexanderSavochkin
AlexanderSavochkin / rotationalmechanics.update.cpp
Last active August 23, 2016 06:29
Rigit body free rotation iteration
class RotationalMechanics
{
mat4 orientation;
mat4 tensorOfInertia;
mat4 iTensorOfInertia;
vec3 angularMomentum;
double width, height, depth;
public:
void update(float dt);
const mat4& getOrientation() const { return orientation; }
@AlexanderSavochkin
AlexanderSavochkin / startup-lpc1114.c
Created April 15, 2016 18:39
Startup code for lpc1114 MCU in C
void Default_Handler(void);
void init();
const void * Vectors[] __attribute__((section(".vectors"))) ={
(void *)0x10002000, /* Top of stack */
init, /* Reset Handler */
Default_Handler, /* NMI */
Default_Handler, /* Hard Fault */
0, /* Reserved */
0, /* Reserved */
@AlexanderSavochkin
AlexanderSavochkin / startup-lpc1114.s
Last active April 15, 2016 04:40
LPC1114 startup code in assembly
.syntax unified
/*Инструктируем транслятор генерировать 16-битные инструкции Thumb*/
.thumb
/*То же самое что ключ командной строки -mcpu=cortex-m0 .
Говорим транслятору, что хотим код под архитектуру Cortex-M0*/
.cpu cortex-m0
/* Опрделяем секцию .vectors, в которой описываем таблицу прерываний */
@AlexanderSavochkin
AlexanderSavochkin / blink-lpc1114.c
Last active April 21, 2016 16:29
LED blink with LPC1114 in C
@AlexanderSavochkin
AlexanderSavochkin / uber-install-213.sh
Created April 12, 2016 03:23 — forked from dannguyen/uber-install-213.sh
Make everything install on Ubuntu 14.04 and 14.10, specifically for AWS and DigitalOcean
## Tested on 14.04 and 14.10. Runs as root because why not
## Installs:
# - Ubuntu developer tools
# - Python (using system 2.7.6 / 2.7.8)
# - scipy libs
# - scikit-learn
# - nltk
# - Ruby 2.1.5
# - rbenv
# - nokogiri
@AlexanderSavochkin
AlexanderSavochkin / blink-lpc1114.ld
Last active March 25, 2016 07:49
LPC1114 minimalistic linker script
@AlexanderSavochkin
AlexanderSavochkin / blink-lpc1114.s
Last active March 25, 2016 17:16
Simple LED blink program for LPC1114 in assembly
void MultinomialLogRelModel::featurize(const valarray<double>& sample_features, int label, valarray<double>& modelFeatures) const
{
for (int k = 0; k < num_classes; ++k) //Loop through classes
{
for (int i = 0; i < num_sample_features; ++i ) //loop through features
{
modelFeatures[k * (num_sample_features + 1) + i] = (k == label ? sample_features[i] : 0.0);
}
modelFeatures[(k + 1) * (num_sample_features + 1) - 1] = (k == label ? 1.0 : 0.0);
}
//Logistic regression example from Saprk documentation
val points = spark.textFile(...).map(parsePoint).cache()
var w = Vector.random(D) // current separating plane
for (i <- 1 to ITERATIONS) {
val gradient = points.map(p =>
(1 / (1 + exp(-p.y*(w dot p.x))) - 1) * p.y * p.x
).reduce(_ + _)
w -= gradient
}
println("Final separating plane: " + w)