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 / 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_compile_windows.md
Last active February 5, 2022 11:43
SFML compile from source on Windows

SFML, Windows, VSCode

SFML compile

  • Download SFML source code from https://www.sfml-dev.org/download.php
  • Download CMake from https://cmake.org/download/
  • Open CMake GUI.
  • Enter source code path to CMake (C:/libs/src/SFML-2.5.1).
  • Enter build path to CMake (C:/libs/src/SFML-2.5.1/build).
  • Press Configure and select MinGW Makefiles and Use default native compilers.
  • Now you have SFML-2.5.1/build folder and makefile in there, open terminal inside the new build folder and type: mingw32-make.
@Mulperi
Mulperi / sfml_box2d_vscode.md
Last active January 9, 2024 00:09
SFML, Box2D in VSCode (macOS)

SFML, Box2D in VSCode (macOS)

Project structure

  • Create new project folder.
  • Inside of the project folder, create folders include and lib.
  • Create main.cpp with code:
  #include "include/SFML/Graphics.hpp"
  #include "include/box2d/box2d.h"
 int main(){}
@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.
@Mulperi
Mulperi / class.py
Created June 1, 2021 06:23
Python class example
import json
# Define class.
class Todo:
# Define constructor function with parameters.
def __init__(self, id, description):
# Assign parameters.
self.id = id
self.description = description