Skip to content

Instantly share code, notes, and snippets.

View Mulperi's full-sized avatar
🎯
Focusing

Mika Mulperi Lakanen Mulperi

🎯
Focusing
View GitHub Profile
@Mulperi
Mulperi / sfml_gameloop.cpp
Created July 18, 2021 14:09
SFML gameloop
#include "include/SFML/Audio.hpp"
#include "include/SFML/Graphics.hpp"
#include "include/box2d/box2d.h"
#include <iostream>
// g++ -std=c++11 sfml_grid.cpp -o sfml_grid -I include -L lib -l sfml-graphics -l sfml-window -l sfml-system -l sfml-audio -Wl,-rpath ./lib
int main(int, char const **)
{
// Create the main window
@Mulperi
Mulperi / timestmap.py
Last active July 17, 2021 12:36
Python datetime and timestamp
import datetime
# Create utc datetime object.
utcdatetime = datetime.datetime.utcnow()
print(utcdatetime)
# Create unix epoch timestamp from datetime.
milliseconds = int(datetime.datetime.timestamp(utcdatetime) * 1000)
timestamp = datetime.datetime.timestamp(utcdatetime)
print(milliseconds)
@Mulperi
Mulperi / graphs.py
Created July 16, 2021 11:35
Generate graphs in a loop
import os
import matplotlib.pyplot as plt
import numpy as np
my_path = os.path.dirname(os.path.abspath(__file__))
timestamps = [1625086800000,
1625173200000,
1625259600000,
1625346000000,
@Mulperi
Mulperi / state_update.tsx
Created July 16, 2021 04:21
Make sure state is not updated after dismount
useEffect(() => {
let isMounted = true; // Used to make sure we don't make state update after component dismount.
const socket = io('ws://localhost:5000/live');
socket.on('connect', function () {
console.log('CONNECTED');
});
socket.on('disconnect', function () {
console.log('DISCONNECTED');
});
socket.on('update', function (payload: any) {
@Mulperi
Mulperi / generator.py
Created July 15, 2021 15:25
Python generator example
def square_numbers(nums):
for i in nums:
yield(i*i)
mynums = square_numbers([1,2,3])
for num in mynums:
print(num)
@Mulperi
Mulperi / LiveFeedView.tsx
Last active July 15, 2021 09:40
Socket.io client with React
import React, { useState } from 'react';
import FeatureHeading from '../components/FeatureHeading';
import { io } from 'socket.io-client';
import { useEffect } from 'react';
export default function LiveFeedView() {
/** Create socket conenction. */
const [live, setLive] = useState(null);
@Mulperi
Mulperi / sdl2_linux.md
Last active July 1, 2021 09:34
SDL2 on Linux

SDL2 on Linux

Installation

  • sudo apt-get install libsdl2-dev will install the SDL2 development library files. Headers will be in /usr/include/SDL2.
  • sudo apt-get install build-essential to get compilers.
  • Install VSCode from market place.
  • Install VSCode C++ extension.
  • Set "/usr/include" and "/usr/include/SDL2" inside the includePath array in VSCode either for current project or as default include path in settings.
  • Create main.cpp and put this insde:
@Mulperi
Mulperi / sdl2_windows.md
Last active July 1, 2021 07:44
SDL2, easy setup on Windows

SDL2 quick and dirty setup on Windows and MinGW

  • Download development library from https://www.libsdl.org/download-2.0.php
  • From extracted SDL2/i686-w64-mingw32/include folder, copy the SDL2 folder to your project/include (so that inside your project you will have include/SDL2).
  • From SDL2/i686-w64-mingw32/bin folder, copy SDL2.dll to your project root.
  • From SDL2/i686-w64-mingw32/lib folder, copy libSDL2main.a to your project root.

In your project root, create main.cpp with this code:

@Mulperi
Mulperi / sfml_xcode.md
Last active June 28, 2021 10:09
SFML Xcode quick start

SFML in Xcode using project template and frameworks

  • Download SFML for Mac from: https://www.sfml-dev.org/download.php
  • From extracted folder, copy contents of Frameworks and extlibs folders to /Library/Frameworks.
  • From extracted folder, copy templates folder to ~/Library/Developer/Xcode/Templates.
  • Create new project with SFML template and select using of Frameworks instead of dynamic libraries.
  • If building fails, go to Build phases and select For install builds only.
@Mulperi
Mulperi / virtualenv.md
Created June 3, 2021 09:59
Python virtualenv installation on Ubuntu

Python virtual environment installation

  • sudo apt install python3-pip --fix-missing
  • pip3 install virtualenv
  • nano ~/.profile and add the location to path, copy paste this kind of line in the end of the file: PATH="$PATH:/home/mikal/.local/bin" or wherever it is located. After installation, virtualenv lets you know the location.
  • Now you can create virtual environment using virtualenv venv
  • Activate your environment using source venv/bin/activate and you will see (venv) appearing in front of your command prompt.