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
@DataGreed
DataGreed / extractAddressFromURL.js
Created May 5, 2024 22:43
Google Apps Script - extract the coordinates from shortened google maps links to use in Google Sheets
function extractAddressFromURL(url) {
// Find the start of the parameters after '?'
var queryStart = url.indexOf('?') + 1;
// Extract the substring from the start of the parameters to the end of the URL
var queryParams = url.substring(queryStart);
// Split the query parameters into an array of key-value pairs
var pairs = queryParams.split('&');
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i].split('=');
if (pair[0] === 'q' && pair[1]) {
// The MIT License (MIT) - https://gist.github.com/bcatcho/1926794b7fd6491159e7
// Copyright (c) 2015 Brandon Catcho
using System;
// Place this file in any folder that is or is a descendant of a folder named "Scripts"
namespace CatchCo
{
// Restrict to methods only
[AttributeUsage(AttributeTargets.Method)]
public class ExposeMethodInEditorAttribute : Attribute
@DataGreed
DataGreed / gist:d45c97ef1f322b35c110320941fbe26f
Created April 5, 2022 15:56
base model for Django projects with autopopulated date_created and date_modified fields
class BaseModel(models.Model):
"""
Base abstract model that adds created and modified dates.
Inherit from it when defining models.
"""
class Meta:
abstract = True
date_created = models.DateTimeField("Date Created", auto_now_add=True)
@DataGreed
DataGreed / NavMeshUtil.cs
Created October 31, 2020 16:20
Navmesh utils - GetRandomPointInRadius , CalculatePathLength
using UnityEngine.AI;
using UnityEngine;
namespace pro.datagreed.utils
{
public static class NavMeshUtil
{
// Get Random Point on a Navmesh surface in the specified radius
public static Vector3 GetRandomPointInRadius(Vector3 center, float maxDistance)
@DataGreed
DataGreed / distribute.sh
Last active April 5, 2022 16:40
Packages your project for pip and sitributes it (run outside virtual environment)
python3 -m pip install --user --upgrade setuptools wheel
python3 setup.py sdist bdist_wheel
python3 -m pip install --user --upgrade twine
twine upload --repository pypi dist/*
@DataGreed
DataGreed / UnityNavMeshCheck.cs
Last active August 21, 2023 17:59
Checks that NavMeshAgent reached destination or gave up trying
public bool ReachedDestinationOrGaveUp()
{
if (!_navMeshAgent.pathPending)
{
if (_navMeshAgent.remainingDistance <= _navMeshAgent.stoppingDistance)
{
if (!_navMeshAgent.hasPath || _navMeshAgent.velocity.sqrMagnitude == 0f)
{
return true;
public static class Vector2Extension
{
public static Vector2 Rotate(this Vector2 v, float degrees)
{
return Quaternion.Euler(0, 0, degrees) * v;
}
}
var angle = Mathf.PI/2 + Mathf.Atan2(-moveDirection.normalized.y, moveDirection.normalized.x);// * Mathf.Rad2Deg;
main.startRotation = angle; //this has to be set in radians apparantly
@DataGreed
DataGreed / admin.py
Created March 31, 2020 14:47
Django admin action ith an intermidiate page with form example (this one uses django-push-notifications)
class ExtendedDeviceAdmin(DeviceAdmin):
actions = ("send_message", "send_bulk_message", "send_custom_message_bulk", "enable", "disable")
def send_custom_message_bulk(self, request, queryset):
form = None
# TODO: handle situation when results from multiple pages selected (or is it handled automatically in django 2?)
if 'apply' in request.POST: # if user pressed 'apply' on intermediate page
@DataGreed
DataGreed / ulimit.sh
Created March 16, 2020 13:05
file descriptors MacOS
# per terminal session
# check
ulimit -a
# set, e.g. 4096
ulimit -n 4096