Skip to content

Instantly share code, notes, and snippets.

View mrousavy's full-sized avatar
🐍
slime season

Marc Rousavy mrousavy

🐍
slime season
View GitHub Profile
@mrousavy
mrousavy / GetScreenshot.cs
Created January 9, 2017 15:22
Get Image from whole screen (BitmapSource)
public class GetScreenshot{
public static BitmapSource GetScreen(Rectangle coordinates) {
int left = coordinates.Left;
int top = coordinates.Top;
int width = coordinates.Width;
int height = coordinates.Height;
using(var screenBmp = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) {
using(var bmpGraphics = Graphics.FromImage(screenBmp)) {
@mrousavy
mrousavy / Loom.cs
Created January 23, 2017 12:53
XYZ Loom for Unity 3D/2D
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
using System.Threading;
using System.Linq;
[ExecuteInEditMode]
/// <summary>
/// Multithreading support
@mrousavy
mrousavy / guid.c
Created April 28, 2017 09:27
Create a random GUID - C
#include <stdio.h>
#include <unknwn.h>
void wmain(int argc, wchar_t* argv[])
{
GUID guid;
wchar_t wzGuid[39] = { 0 };
int count = (1 < argc) ? _wtoi(argv[1]) : 1;
for (int i = 0; i < count; ++i)
@mrousavy
mrousavy / gitclone.sh
Created June 16, 2017 07:53
Git Clone for mrousavy GitHub
# Console Colors (Green, NoColor)
GREEN='\033[0;32m'
NC='\033[0m'
# GitHub Username
User="mrousavy"
# Get Repo Var
printf "Repo Name: ${GREEN}$User/"
read repo
@mrousavy
mrousavy / gitpull.sh
Created June 16, 2017 07:53
Pull for every subfolder
# Console Colors (Green, NoColor)
GREEN='\033[0;32m'
NC='\033[0m'
# Loop over all Directories
for path in *; do
[ -d "${path}" ] || continue # if not a directory, skip
dirname="$(basename "${path}")"
cd $dirname # Go into Directory
printf "${GREEN}$dirname: ${NC}"
@mrousavy
mrousavy / GetAllReferences.cs
Last active July 13, 2017 15:01
Get ALL references that can be found in the current Assembly, excluding own references (takes ~400ms on 34 .NET (core) references)
/// <summary>
/// Load all references/namespaces that can be found in this assembly (excluding own references)
/// </summary>
public static string[] LoadReferences()
{
//Get all namespaces from this assembly (own project, own library, ..)
IEnumerable<string> ownNamespaces = Assembly.GetExecutingAssembly().GetTypes()
.Select(t => t.Namespace)
.Distinct();
@mrousavy
mrousavy / AnimationExtensions.cs
Created August 21, 2017 10:23
Useful async extensions for WPF UIElements/Animatable for animating with ease
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Animation;
namespace mrousavy {
public static class AnimationExtensions {
/// <summary>
/// Animate a given <see cref="UIElement" />/<see cref="System.Windows.Controls.Control" /> asynchronous (awaitable)
/// </summary>
@mrousavy
mrousavy / CSharpSyntax.xshd
Created August 21, 2017 10:25
C# RegEx based (No AST) syntax highlighting
<SyntaxDefinition name="CSharp" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
<Color name="CommentSingle" foreground="#0cad31" />
<Color name="CommentMulti" foreground="#068724" />
<Color name="String" foreground="Orange" />
<Color name="Char" foreground="DarkOrange" />
<Color name="Digits" foreground="DarkBlue"/>
<RuleSet>
<Span color="CommentSingle" begin="//" />
@mrousavy
mrousavy / RelayCommand.cs
Created September 25, 2017 07:56
An event basede ICommand implementation for WPF
using System;
using System.Windows.Input;
public class RelayCommand : ICommand {
private readonly Predicate<object> _canExecute;
private readonly Action<object> _execute;
public RelayCommand(Action<object> execute, Predicate<object> canExecute = null) {
_execute = execute ?? throw new ArgumentNullException(nameof(execute));
_canExecute = canExecute ?? (o => true);
@mrousavy
mrousavy / file_io.h
Created November 11, 2017 17:58
C++ filestream Input/Output functions for numbers (32bit, 16bit and 8bit reading and writing) with bit flipping (Little -> Big endian)
#pragma once
#include <stdio.h>
#include <fstream>
#include <stdint.h>
inline uint32_t read_big_int(std::fstream &fileStream) {
unsigned char bytes[4];
fileStream.read((char*)bytes, 4);
return (uint32_t)((bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3]);