Skip to content

Instantly share code, notes, and snippets.

@ProGM
ProGM / arel_cheatsheet_on_steroids.md
Last active April 19, 2024 04:06
Arel cheatsheet on Steroids

Arel Cheatsheet on Steroids

A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.

Tables

posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord

Table alias

@ProGM
ProGM / ExampleBehavior.cs
Created October 19, 2016 10:39
A PropertyDrawer to show a popup field with a generic list of string for your Unity3d attribute
public class MyBehavior : MonoBehaviour {
// This will store the string value
[StringInList("Cat", "Dog")] public string Animal;
// This will store the index of the array value
[StringInList("John", "Jack", "Jim")] public int PersonID;
// Showing a list of loaded scenes
[StringInList(typeof(PropertyDrawersHelper), "AllSceneNames")] public string SceneName;
}
@ProGM
ProGM / CheckMissingReferencesInUnity.cs
Last active July 18, 2023 14:22
Finding Missing References in Unity 5.4+
// Based on http://www.tallior.com/find-missing-references-unity/
// It fixes deprecations and checks for missing references every time a new scene is loaded
// Moreover, it inspects missing references in animators and animation frames
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
using System.Linq;
[InitializeOnLoad]
@ProGM
ProGM / DraggablePoint.cs
Last active April 25, 2023 07:45
A Unity Editor extension to generate draggable points for vector3 serialized attributes.
using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class DraggablePoint : PropertyAttribute {}
#if UNITY_EDITOR
@ProGM
ProGM / FloodFill.cs
Last active December 29, 2022 03:13
A simple Flood Fill implementation for Unity3D C# for video games. https://elfgames.com/2016/12/14/identify-unwanted-maze-solutions-using-flood-fill-with-unity3d/
// Copyright (c) 2022 Piero Dotti, Elf Games
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
@ProGM
ProGM / ac_streams_bench.rb
Last active June 8, 2022 19:46 — forked from palkan/ac_streams_bench.rb
ActionCable Streaming Benchmark
# rubocop disable:all
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
@ProGM
ProGM / Cookbook
Created May 15, 2022 19:18
DSL Example in Ruby
recipe :pasta do
add 1.liter, of: :water, in: :pot
turn_on :fire
wait_until :pot, :boiling?
add 1.gram, of: :salt, in: :pot
wait 1.minute
add 150.grams, of: :pasta, in: :pot
@ProGM
ProGM / example.ts
Last active March 30, 2022 20:36
New Model Parser for JSON::API. Used as a bases for: https://github.com/monade/json-api-parser
import { Parser } from './parser';
import 'models';
const parsable = `{
"data": [
{
"id": "2", "type": "posts",
"attributes": { "name": "My post", "ciao": null, "description": "ciao", "created_at": "2020-10-10T10:32:00Z" },
"relationships": { "user": { "data": { "id": "3", "type": "users" } } }
}
@ProGM
ProGM / find_useless_resources_unity.sh
Last active January 8, 2022 10:04
A useful script to identify Unity resource that are not referenced in the project
#!/bin/bash
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
NC='\033[0m'
rm unused_files.log &> /dev/null
grep -r . --include=\*.meta --exclude=*{Editor,Gizmos}* -e 'guid' | while read line; do
@ProGM
ProGM / cache.ts
Created December 22, 2021 10:57
Cache getters in Angular, similar to computed in Vue, using memoizee
import * as memoizee from 'memoizee';
var objIdMap = new WeakMap, objectCount = 0;
function objectId(object: any){
if (!objIdMap.has(object)) { objIdMap.set(object,++objectCount); }
return objIdMap.get(object);
}