Skip to content

Instantly share code, notes, and snippets.

View NickDiMucci's full-sized avatar

Nicholas DiMucci NickDiMucci

View GitHub Profile
@NickDiMucci
NickDiMucci / Enemy.cs
Last active December 14, 2015 06:08
How to get around the inability to have constructor parameters in Unity
public EnemyBullet bullet;
private void fireBullet() {
EnemyBullet enemyBullet = Instantiate(bullet, gun.position, gun.rotation) as EnemyBullet;
enemyBullet.setSpeed(speed + BULLET_SPEED_MULTIPLIER);
laser.Play();
}
@NickDiMucci
NickDiMucci / EnemyBullet.cs
Created February 26, 2013 16:53
Setting the speed in Start
void Start() {
speed = 15.0f;
// Other code here...
}
@NickDiMucci
NickDiMucci / Enemy.cs
Last active December 14, 2015 06:38
Example showing GetComponent usage to access a prefab's script.
public Transform bullet;
private void fireBullet() {
Transform gameObject = Instantiate(bullet, gun.position, gun.rotation) as Transform;
gameObject.GetComponent<EnemyBullet>().setSpeed(speed + BULLET_SPEED_MULTIPLIER);
laser.Play();
}
using strange.extensions.mediation.impl;
[Mediates(typeof($VIEW$))]
public class $MEDIATOR$ : Mediator
{
[Inject]
public $VIEW$ view { get; set; }
public override void OnRegister()
{
@NickDiMucci
NickDiMucci / BitmapToTexture2D.cs
Last active June 18, 2017 09:01
Get a Texture2D from a Bitmap image.
public static Texture2D BitmapToTexture2D(GraphicsDevice GraphicsDevice, System.Drawing.Bitmap image)
{
// Buffer size is size of color array multiplied by 4 because
// each pixel has four color bytes
int bufferSize = image.Height * image.Width * 4;
// Create new memory stream and save image to stream so
// we don't have to save and read file
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(bufferSize);
image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
@NickDiMucci
NickDiMucci / PlayerMovementDwS.cs
Created March 2, 2018 14:40
The player movement and collision detection code for Demons with Shotguns.
namespace com.mindshaft.overtime.controller {
public class BasicEntityController : IEntityController {
private float gravity = 40f;
private float targetSpeed = 0f;
private IMovementModel model;
[Inject]
public IEntityCollisionDetection CollisionDetection { get; set; }
@NickDiMucci
NickDiMucci / unityBuildWindows.bat
Created August 25, 2014 14:30
Script to automate build the Windows player of a Unity project, and committing build to a git repo.
@echo off
set PROJECT=-projectPath
set PROJECT_PATH="C:\path\to\your\Unity\project"
set WIN_PATH="C:\path\to\your\game.exe"
@REM Common options
set BATCH=-batchmode
set QUIT=-quit
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import pandas as p
# Data source https://www.kaggle.com/lazyjustin/pubgplayerstats/data
colnames = ['player_name','tracker_id','solo_KillDeathRatio','solo_WinRatio','solo_TimeSurvived','solo_RoundsPlayed','solo_Wins','solo_WinTop10Ratio','solo_Top10s','solo_Top10Ratio','solo_Losses','solo_Rating','solo_BestRating','solo_DamagePg','solo_HeadshotKillsPg','solo_HealsPg','solo_KillsPg','solo_MoveDistancePg','solo_RevivesPg','solo_RoadKillsPg','solo_TeamKillsPg','solo_TimeSurvivedPg','solo_Top10sPg','solo_Kills','solo_Assists','solo_Suicides','solo_TeamKills','solo_HeadshotKills','solo_HeadshotKillRatio','solo_VehicleDestroys','solo_RoadKills','solo_DailyKills','solo_WeeklyKills','solo_RoundMostKills','solo_MaxKillStreaks','solo_WeaponAcquired','solo_Days','solo_LongestTimeSurvived','solo_MostSurvivalTime','solo_AvgSurvivalTime','solo_WinPoints','solo_WalkDistance','solo_RideDistance','solo_MoveDistance','solo_AvgWalkDistance','solo_AvgRid

My largest Sidekiq application had a memory leak and I was able to find and fix it in just few hours spent on analyzing Ruby's heap. In this post I'll show my profiling setup.

As you might know Ruby 2.1 introduced a few great changes to ObjectSpace, so now it's much easier to find a line of code that is allocating too many objects. Here is great post explaining how it's working.

I was too lazy to set up some seeding and run it locally, so I checked that test suite passes when profiling is enabled and pushed debugging to production. Production environment also suited me better since my jobs data can't be fully random generated.

So, in order to profile your worker, add this to your Sidekiq configuration:

if ENV["PROFILE"]
@NickDiMucci
NickDiMucci / BasicEntityCollision.cs
Last active May 16, 2021 06:54
Basic collision detection via ray casting in Unity.
public class BasicEntityCollision : IEntityCollision {
private Vector3 size;
private Vector3 center;
// Give a bit of space between the raycast and boxCollider to prevent ray going through collision layer.
private float skin = .005f;
private LayerMask collisionMask;
private LayerMask playerMask;
public bool OnGround { get; set; }