Skip to content

Instantly share code, notes, and snippets.

View Tymski's full-sized avatar
💼
Making games

Tymon Oziemblewski Tymski

💼
Making games
View GitHub Profile
@Tymski
Tymski / pipe.js
Last active August 2, 2017 14:50
JavaScript pipe, object oriented pipe declaration with example, pipeline
//Pipe definition:
Object.defineProperty(Object.prototype, 'pipe',{
value: function(...f){ return f.reduce((val, fun) => fun(val), this)},
writable: true,
configurable: true,
enumerable: false
});
//Easier logging to console:
log = console.log;
@Tymski
Tymski / kropki.js
Created April 26, 2018 20:52
gra w kropki
createArray = (x, y, fill = 0) => {
for (var ary = []; ary.push(Array(x).fill(fill)) < y;);
return ary;
}
board = createArray(10, 10, 3);
display = (ary = board) => console.table(ary) // function that draws the board in the console
has4 = (ary) => ary.filter(x => x >= 4).length > 0 // Is there a 4 or more in 1 dimensional array?
Has4 = (ary = board) => ary.filter((x) => has4(x)).length > 0 // Is there a 4 or more in 2 dimensional array?
split = () => {
let board2 = createArray(10, 10);
@Tymski
Tymski / ScreenCaptureEditor.cs
Last active September 24, 2021 13:36
Unity make a screenshot from editor
using System.IO;
using UnityEditor;
using UnityEngine;
public class ScreenCaptureEditor : EditorWindow
{
private static string directory = "Screenshots/Capture/";
private static string latestScreenshotPath = "";
private bool initDone = false;
@Tymski
Tymski / Create a new feature
Last active October 16, 2020 11:35
Some git flow commands
// Create a bew branch and move there
git checkout -b feature/myAwesomeFunctionality develop
// ... Implement the feature, add, commit, as normal
// push changes
git push --set-upstream origin feature/myAwesomeFunctionality
@Tymski
Tymski / WorkingAspectRatioFitter.cs
Last active April 13, 2021 22:09
When you put an AspectRatioFitter inside a LayoutGroup, it breaks your layout. This is a fix for this.
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(AspectRatioFitter))]
[RequireComponent(typeof(RectTransform))]
[ExecuteInEditMode]
public class WorkingAspectRatioFitter : MonoBehaviour
{
AspectRatioFitter aspectRatioFitter;
RectTransform rectTransform;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// Use a number of cells and columns instead of cell width and height
/// </summary>
[RequireComponent(typeof(GridLayoutGroup))]
[ExecuteInEditMode]
public class GridLayoutGroupCells : MonoBehaviour
{
using UnityEngine;
public static class SingletonInitializer
{
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
static void InitializeSingletons()
{
var singletons = Resources.Load<GameObject>("SINGLETONS");
Object.DontDestroyOnLoad(Object.Instantiate(singletons));
}