Skip to content

Instantly share code, notes, and snippets.

View mortennobel's full-sized avatar

Morten Nobel-Jørgensen mortennobel

View GitHub Profile
@mortennobel
mortennobel / awk.sh
Last active December 12, 2015 10:09
replaces blocks of text surrounded by start and end symbol with a constant line (useful for simple preprocessing scripts)
awk '/insert_code_start/,/insert_code_end/ { if ( $0 ~ /insert_code_end/) print " // insert code here"; next} 1' < test.cpp > text_sub.cpp
#
# Example
#
# void main(){
# // insert_code_start
# foo();
# // insert_code_end
@mortennobel
mortennobel / observer.cpp
Last active December 16, 2015 03:39
Observer pattern in C++11
//
// main.cpp
// Observer pattern in C++11
//
// Created by Morten Nobel-Jørgensen on 9/21/12.
// Copyright (c) 2012 Morten Nobel-Joergensen. All rights reserved.
//
#include <iostream>
#include <functional>
#include <deque>
#include <mutex>
// Reuseable blocking queue
template <typename T> class BlockingQueue {
std::deque<T> q;
std::mutex m;
std::condition_variable cv;
public:
#-------------------------------------------------
#
# Project created by QtCreator 2013-07-08T13:26:39
#
#-------------------------------------------------
QT += core gui widgets opengl network
TARGET = QtImageCompressionTest
CONFIG += console
@mortennobel
mortennobel / cpp11shim.h
Created July 22, 2013 13:54
c++11 shim (allows you to use a C++11 compiler with the stdlibc++ without C++11 support ... useful when depending on old libraries).
//
// cpp11shim.h
//
// Created by Morten Nobel-Jørgensen on 7/19/13.
// Copyright (c) 2013 Morten Nobel-Joergensen. All rights reserved.
//
#ifndef __CPP11_SHIM__
#define __CPP11_SHIM__
@mortennobel
mortennobel / plasma.c
Created October 17, 2013 06:57
plasma effect (from Unity's RenderingPluginExample42)
// Simple oldskool "plasma effect", a bunch of combined sine waves
// input x,y (uv-coordinates), t (time)
int vv = int(
(127.0f + (127.0f * sinf(x/7.0f+t))) +
(127.0f + (127.0f * sinf(y/5.0f-t))) +
(127.0f + (127.0f * sinf((x+y)/6.0f-t))) +
(127.0f + (127.0f * sinf(sqrtf(float(x*x + y*y))/4.0f-t)))
) / 4;
@mortennobel
mortennobel / Make environment definitions.txt
Created January 15, 2016 11:57
Make environment definitions
# Using standard definitions from the make environment, typically:
#
# CC cc C compiler
# CXX g++ C++ compiler
# CFLAGS [ ] flags for C and C++ compiler
# CPPFLAGS [ ] flags for C and C++ compiler
# TARGET_ARCH [ ] target architecture
# FFLAGS [ ] flags for Fortran compiler
# RM rm -f delete a file
# AR ar create a static *.a library archive
@mortennobel
mortennobel / encode_image.sh
Created April 24, 2016 18:32
Encode png images as movie
# Loosely based on http://superuser.com/a/533706
ffmpeg -framerate 10 -i shot\ %04d.png -s:v 1280x720 -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p smart-avenue-1.mp4
using UnityEngine;
using System.Collections;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Text;
public class HelloSocketWorld : MonoBehaviour {
public string history;
public string txt;
@mortennobel
mortennobel / timer.cpp
Last active October 30, 2016 19:52
C++11 timer
#include <iostream>
#include <chrono>
using namespace std;
// Based on http://stackoverflow.com/a/5524138/420250
int main()
{
typedef std::chrono::high_resolution_clock Clock;
using FpMilliseconds = std::chrono::duration<float, std::chrono::milliseconds::period>;