Skip to content

Instantly share code, notes, and snippets.

View embiem's full-sized avatar

Martin Beierling-Mutz embiem

View GitHub Profile
@embiem
embiem / UE4 Get Look Direction
Created June 24, 2016 07:24
A function to get the look rotation by supplying it with a screen location (e.g. half the viewportSize, to use the middle of the screen). Useful for crosshairs
bool GetLookDirection(FVector2D ScreenLocation, FVector& LookDirection) const
{
FVector CameraWorldLocation;
return DeprojectScreenPositionToWorld(
ScreenLocation.X,
ScreenLocation.Y,
CameraWorldLocation,
LookDirection
);
}
bool GetSightRayHitLocation(FVector& HitLocation) const
{
// Find crosshair position in pixel coordinates
int32 ViewportSizeX, ViewportSizeY;
GetViewportSize(ViewportSizeX, ViewportSizeY);
FVector2D ScreenLocation = FVector2D(ViewportSizeX * CrossHairXLocation, ViewportSizeY * CrossHairYLocation);
// "De-project" the screen position of the crosshair to a world direction
FVector LookDirection, LookStartLocation;
@embiem
embiem / cartpole_qlearner.py
Created February 9, 2017 11:14
OpenAI Gym Q-Learner for the cartpole environment
'''
Very basic Q-Learner that is tailored for the cart-pole environment.
This implementation leaves a lot of space for improvements.
'''
import gym
from gym import wrappers
import math
@embiem
embiem / TagInput.css
Created April 20, 2017 13:50
TagInput-Component for React
.tags-input {
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-content: flex-start;
justify-content: center;
}
.tags-input .tag-entry {
user-select: none;
cursor: pointer;
@embiem
embiem / Logger.js
Created May 5, 2017 12:14
Custom logging via ES6 class. Extendable.
class Logger {
constructor() {
if (!Logger.instance) {
Logger.instance = this;
}
return Logger.instance;
}
log(...args) {
console.log(...args);
@embiem
embiem / AdobeButton.js
Created June 23, 2017 08:06
Adobe App-styled button as a React Component
import React, { Component } from 'react';
import './AdobeButton.css';
/**
* Adobe-Style button
*/
class AdobeButton extends Component {
render() {
const { text, onClick } = this.props;
@embiem
embiem / codelabs_spider.py
Last active August 27, 2020 09:33
Scrapy Spider that scrapes Google's Codelabs for Category, Description, Link, Last Updated, Duration and Tags.
import scrapy
class CodelabsSpider(scrapy.Spider):
name = "codelabs"
def start_requests(self):
urls = [
'https://codelabs.developers.google.com/'
]
for url in urls:
@embiem
embiem / DynamicScale.cs
Created July 5, 2017 11:39
Stretch object based on its speed and movement direction (original by @_pikopik https://twitter.com/_pikopik/status/882346033656844288) #Unity
using UnityEngine;
[ExecuteInEditMode]
public class DynamicScale : MonoBehaviour
{
Vector3 lastPosition;
void Start()
{
lastPosition = transform.position;
@embiem
embiem / Lane.cpp
Last active August 26, 2020 02:53
Equally distributed Spline Mesh in UE4
// Used further down in the OnConstruction call to set values on one spline mesh
void ALane::BuildTrackElement(int32 atDistance, USplineMeshComponent* SplineMesh, UStaticMesh* LaneElementMesh, ESplineMeshAxis::Type LaneElementMeshForwardAxis)
{
FVector currLocation, currTangent, nextLocation, nextTangent;
currLocation = SplineComponent->GetLocationAtDistanceAlongSpline(atDistance, ESplineCoordinateSpace::Type::Local);
currTangent = SplineComponent->GetTangentAtDistanceAlongSpline(atDistance, ESplineCoordinateSpace::Type::Local);
nextLocation = SplineComponent->GetLocationAtDistanceAlongSpline(atDistance + MeshSpacing, ESplineCoordinateSpace::Type::Local);
nextTangent = SplineComponent->GetTangentAtDistanceAlongSpline(atDistance + MeshSpacing, ESplineCoordinateSpace::Type::Local);
@embiem
embiem / generate_local_ssl.bat
Created September 14, 2017 19:50
modified OpenSSL config & batch file to generate self-signed certificate for Twitch extension development
openssl req -newkey rsa:4096 -days 1001 -nodes -x509 -subj "/C=US/ST=California/L=San Francisco/O=Twitch/OU=web/CN=localhost" -extensions SAN -config ".\openssl.cnf" -keyout "testing.key" -out "testing.crt"