Skip to content

Instantly share code, notes, and snippets.

@joastbg
joastbg / build.bat
Created October 18, 2018 20:06
MIDL - Microsoft Interface Definition Language
echo "compiling MIDL..." :: Make sure tools are in PATH (eg Developer Command Prompt for VS 2017)
midl myfilectl.idl /tlb myfilectl.tlb
echo "done."
@joastbg
joastbg / sun_earth.m
Created December 2, 2017 10:28
Estimating earth surface temperature from variation in sun spot density
% Refs:
% 1. https://en.wikipedia.org/wiki/Stefan%E2%80%93Boltzmann_law#cite_note-Solar_constant_at_ground_level-9
% 2. https://en.wikipedia.org/wiki/Sunspot
% Kelvin
K = 273.15;
% sun earch distance
r = 149600000; % meters
@joastbg
joastbg / myecho.my
Created November 17, 2017 11:12
Echo effect in MATLAB
[y, Fs] = audioread('01_DJ.wav');
h = [1, zeros(1,0.4*Fs), 0.5, zeros(1,0.4*Fs), 0.2];
plot(h)
out = conv((y(:,1)+y(:,2))/2,h);
sound(out,Fs);
plot(out);
@joastbg
joastbg / experiments.py
Created October 8, 2016 16:16
Numpy experiments
# Computing angles of complex eigenvalues for some random matrices
for i in range(60):
M = np.matrix(np.random.rand(10,10))
w, v = LA.eig(M)
args = np.angle(w, deg=True)
print("\t\t".join(map(lambda x:str(round(x, 2)), args)))
@joastbg
joastbg / qrnd.cc
Created October 4, 2016 22:15
Entropy of Quantum random numbers
#include <iostream>
#include <iterator>
#include <fstream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <limits>
#include <iomanip>
#include <string>
@joastbg
joastbg / fun.cc
Created October 4, 2016 20:19
Fun with x87 instructions using inline assembly (Intel syntax)
// g++ fun.cc -masm=intel
float fpzero = 0;
unsigned long pfpzero = (unsigned long)&fpzero;
__asm__ volatile("xorps xmm1, xmm1");
__asm__ volatile("fldpi"); // load PI
__asm__ volatile("fchs"); // change sign
__asm__ volatile("fst dword ptr [%0]":"=&r"(pfpzero));
// this should be -3.14159...
@joastbg
joastbg / opengl2D.cpp
Last active April 8, 2023 08:49
OpenGL 2D
#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <thread>
#include <string>
#include <chrono>
#include <GL/glut.h>
#include <GL/glu.h>
@joastbg
joastbg / epoll_http_server.c
Created August 11, 2016 16:06
Epoll + Lua
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#!/usr/bin/perl
use strict;
use warnings;
use locale;
use utf8;
#use open qw(:std :utf8);
#use feature 'unicode_strings';
use Cassandra::Lite;
@joastbg
joastbg / sg_test.py
Created August 6, 2016 03:03
Sendgrid in Python
import sendgrid
import os
from sendgrid.helpers.mail import *
sg = sendgrid.SendGridAPIClient(apikey="...")
from_email = Email("joastbg@gmail.com")
to_email = Email("joastbg@gmail.com")
subject = "Please activate your ABC account"
content = Content("text/html", "<h1>Welcome to ABC</h1>Please click this <a href=\"http://www.abc.com/activate/32132112121\">link</a> to activate your account!")
mail = Mail(from_email, subject, to_email, content)