Skip to content

Instantly share code, notes, and snippets.

View DataGreed's full-sized avatar
👾
practicing magic

Alexey Strelkov DataGreed

👾
practicing magic
View GitHub Profile
class MulticastDelegate:
def __init__(self):
self.delegates = []
def add(self, delegate):
self.delegates.append(delegate)
def sub(self, delegate):
self.delegates.remove(delegate)
@DataGreed
DataGreed / decrypt_message.js
Created June 23, 2017 23:56
PubNub blocks message decrypting (very ugly but works)
export default (request) => {
console.log('--------------------------------------------START')
////////////////////////////////
// ---------- external modules
// sha256
function SHA256(s){
var chrsz = 8;
#!/bin/env sh
lines=$(tput lines)
cols=$(tput cols)
awkscript='
{
letters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*()"
lines=$1
@DataGreed
DataGreed / GameController.cs
Last active January 15, 2019 02:38
Unity Singleton implementation for GameController, based on Flappy Bird Tutorial.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameController : MonoBehaviour
{
public static GameController instance;
// Singleton Initialization
void Awake()
@DataGreed
DataGreed / RendererExtensions.cs
Created January 17, 2019 21:46
An extension class for Unity Renderer that checks if it's seen from a specified camera
using UnityEngine;
public static class RendererExtensions
{
/// <summary>
/// Checks if the object is visible from a certain camera
/// </summary>
/// <returns><c>true</c>, if visible, <c>false</c> otherwise.</returns>
/// <param name="renderer">Object Renderer</param>
/// <param name="camera">Camera</param>
@DataGreed
DataGreed / OverrideSortingLayer.cs
Created January 22, 2019 02:42
Simple script to correct sorting z-sorting for Unity games using both 2d SPrites and 3D-meshes. Adds a property for the mesh that lets you specify its sorting layer
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Used to set Sorting Layer for 3D meshes, so they can Z-sort
/// correctly when used with 2D Sprites.
/// </summary>
public class OverrideSortingLayer : MonoBehaviour
{
@DataGreed
DataGreed / WeightedRandomBag.cs
Created January 31, 2019 02:25
Weighted random choice - C# implementation
using System;
using System.Collections.Generic;
class WeightedRandomBag<T> {
private struct Entry {
public double accumulatedWeight;
public T item;
}
@DataGreed
DataGreed / gist:e152dc76eb4a13bb5db587c76867a75e
Created January 31, 2019 20:33
disable logging in unity of the project is run in external player (not editor)
#if UNITY_EDITOR
Debug.unityLogger.logEnabled = true;
#else
Debug.unityLogger.logEnabled = false;
#endif
@DataGreed
DataGreed / placeholder.cs
Created March 9, 2019 21:08
Unity Send Email (supports mobile)
using UnityEngine.Networking;
/// <summary>
/// Opens external application to send an email
/// </summary>
/// <param name="email">Email address</param>
/// <param name="subject">Subject.</param>
/// <param name="body">Body. E.g "My Body\r\nFull of non-escaped chars"</param>
void SendEmail(string email, string subject, string body)
{
@DataGreed
DataGreed / placeholder.cs
Created March 10, 2019 13:25
Unity: Custom Event handler in script editor panel
using UnityEngine.Events;
//will be displayed in editor
public UnityEvent yourCustomEvent;
public void Foo() {
// Trigger the event!
yourCustomEvent.Invoke();
}