Skip to content

Instantly share code, notes, and snippets.

@rikusalminen
rikusalminen / gist:972e3824350193bbed0c28ff96a82a73
Created September 10, 2016 16:24
Linux force feedback hello world
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <linux/input.h>
@rikusalminen
rikusalminen / pymesh.py
Created January 19, 2018 08:05
Triangle meshes with Python and pygame
import pygame
import pygame.freetype
import pygame.gfxdraw
quadrants = (
(( 0, 0), (+1, -1), (+1, +1)),
(( 0, 0), (+1, +1), (-1, +1)),
(( 0, 0), (-1, +1), (-1, -1)),
(( 0, 0), (-1, -1), (+1, -1)))
@rikusalminen
rikusalminen / simd.c
Created June 26, 2012 07:48
Some 3D math with x86 SIMD: SSE, AVX, FMA, et al
#include <stdint.h>
#include <x86intrin.h>
#include <stdio.h>
void printv(__m128 vec)
{
float x[4];
@rikusalminen
rikusalminen / gist:1106628
Created July 26, 2011 12:24
multithreaded glx
#include <stdbool.h>
#include <stdio.h>
#include <X11/Xlib.h>
#include <GL/glx.h>
#include <GL/glxext.h>
#include <GL/gl.h>
GLXContext glXCreateContextAttribsARB(
Display *dpy, GLXFBConfig config,
@rikusalminen
rikusalminen / frontpage.tex
Last active April 21, 2022 19:43
Celestial mechanics cheat sheet
% vim:nolist lbr tw=78 expandtab
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[landscape,top=1cm,bottom=1cm,left=1cm,right=1cm]{geometry}
\usepackage[tiny]{titlesec} % smaller titles
\usepackage{multicol}
\usepackage{amsmath}
\pagestyle{empty}
@rikusalminen
rikusalminen / cube.glslv
Last active January 26, 2022 15:24
Cube vertex shader - usage: glDrawArrays(GL_TRIANGLES, 0, 36), disable all vertex arrays
#version 420
uniform mat4 projection_matrix;
uniform mat4 model_matrix;
void main()
{
int tri = gl_VertexID / 3;
int idx = gl_VertexID % 3;
int face = tri / 2;
@rikusalminen
rikusalminen / pyrocket.py
Created July 31, 2014 09:28
Solving the rocket equation in Python
def numerical():
from scipy.integrate import odeint
from numpy import array
# [position, mass, velocity, mass flow]
def acceleration(y, t, v_exhaust=1.0):
return array([y[2], y[3], v_exhaust * y[3]/y[1], 0.0])
initial_state = array([0.0, 2.0, 0.0, -1.0])
@rikusalminen
rikusalminen / trampoline.ll
Created January 31, 2013 11:55
LLVM trampoline fun
declare void @llvm.init.trampoline(i8*, i8*, i8*);
declare i8* @llvm.adjust.trampoline(i8*);
define i32 @foo(i32* nest %ptr, i32 %val)
{
%x = load i32* %ptr
%sum = add i32 %x, %val
ret i32 %sum
}
@rikusalminen
rikusalminen / dot.c
Created July 3, 2012 14:55
SIMD dot products: ARM NEON, SSE3, SSE
#if defined(__ARM_NEON__)
vec4 dot(vec4 a, vec4 b)
{
vec4 prod = vmulq_f32(a, b);
vec4 sum1 = vaddq_f32(prod, vrev64q_f32(prod));
vec4 sum2 = vaddq_f32(sum1, vcombine_f32(vget_high_f32(sum1), vget_low_f32(sum1)));
return sum2;
}
#else if defined(__SSE3__)
static inline vec4 vdot(vec4 x, vec4 y)
@rikusalminen
rikusalminen / kepler.hs
Last active April 5, 2020 15:20
Computing Kepler's elements with Haskell
module Main where
import Debug.Trace
import Control.Monad (forM_)
epsilon = 1.0e-10 :: Double
add (x1, y1, z1) (x2, y2, z2) = (x1+x2, y1+y2, z1+z2)
sub (x1, y1, z1) (x2, y2, z2) = (x1-x2, y1-y2, z1-z2)
mul (x1, y1, z1) (x2, y2, z2) = (x1*x2, y1*y2, z1*z2)