Skip to content

Instantly share code, notes, and snippets.

View olafurjohannsson's full-sized avatar

Ólafur Aron Jóhannsson olafurjohannsson

  • Tern Systems
  • Reykjavík
View GitHub Profile
@olafurjohannsson
olafurjohannsson / geodetic2ecef.hpp
Created January 9, 2019 11:19
C++ geodetic2ecef - lat lon to cartesian, assuming an ellipsoid
#include <math.h>
constexpr double R = 6378.137;
constexpr double ESQ (6.69437999014 * 0.001);
constexpr double DEG2RAD = M_PI / 180.0;
template<typename T>
struct point {
using coordinate_type = T;
T x;
@olafurjohannsson
olafurjohannsson / gist:d382e585613b4b09a1dadad53ee95153
Created November 1, 2018 21:22
Scrreen coordinates to normalized coordinates, WebGL specific
function screenToNdc(x, y) {
return [(x / window.innerWidth) * 2 - 1, (y / window.innerHeight) * 2 + 1];
}
@olafurjohannsson
olafurjohannsson / requestmanager.cpp
Last active July 26, 2023 13:43
Asynchronous HTTP network requests in C++ with Qt
#include "requestmanager.h"
///
/// RequestManager constructor
///
/// Description: sets up a network access manager that
/// abstract the HTTP/TCP protocol
RequestManager::RequestManager(QObject *parent) : QObject(parent)
{
@olafurjohannsson
olafurjohannsson / stdlib.c
Last active August 3, 2016 22:32
C stdlib functions
#include "stdlib.h"
/*
* string_length:
* Returns the length of the pointer *s
* Same as strlen in <stdlib>
*/
unsigned long string_length(const char *s) {
int c = 0;
// dereference the pointer until EOF and raise the counter variable
@olafurjohannsson
olafurjohannsson / scanner.py
Created July 10, 2016 11:34
Scan TCP ports on a network with Python
# -*- coding: utf-8 -*-
"""
@author: Ólafur Aron Jóhannsson
@email: olafur@johannsson.co
"""
import optparse, nmap, re
from socket import *
from threading import *
@olafurjohannsson
olafurjohannsson / email.go
Created July 10, 2016 11:31
Send email with Go
package EmailSender
import (
"net/smtp"
"strconv"
)
type EmailSender interface {
Send() error
@olafurjohannsson
olafurjohannsson / RequestManager.cs
Last active December 15, 2021 13:34
C# asynchronous HTTP GET and POST method wrapped nicely in a RequestManager class - it memory caches it's requests via the Cache class
/// <summary>
/// Reqeust manager encapsulates asynchronous HTTP GET and POST methods
/// In conjunction with that, it internally caches requests made in the same minute
/// </summary>
public class RequestManager
{
private Dictionary<string, string> CustomHeaders = null;
public RequestManager(Dictionary<string, string> customHeaders = null)
{
@olafurjohannsson
olafurjohannsson / send_email.py
Last active August 3, 2016 22:37
Send email with python
def send_email(to, _from, subject, message):
msg = "\r\n".join([
"From: " + _from,
"To: " + to,
"Subject: " + subject,
"",
message
])
server = smtplib.SMTP(SMTP_SERVER)
server.ehlo()