Skip to content

Instantly share code, notes, and snippets.

View Bocom's full-sized avatar

Benjamin Röjder Delnavaz Bocom

View GitHub Profile
@Bocom
Bocom / multiple-file-extensions.php
Created August 23, 2022 19:08
Checks whether string contains multiple file extensions
<?php
str_contains(ltrim(strstr($input, '.'), '.'), '.');
@Bocom
Bocom / files.rs
Created February 28, 2020 00:28
nushell dir_entry_dict with optional metadata
pub(crate) fn dir_entry_dict(
filename: &std::path::Path,
metadata: Option<&std::fs::Metadata>,
tag: impl Into<Tag>,
full: bool,
name_only: bool,
with_symlink_targets: bool,
) -> Result<Value, ShellError> {
let tag = tag.into();
let mut dict = TaggedDictBuilder::new(&tag);
public class Something
{
public delegate void TestAction(); // This is how UnityAction is defined according to Unity docs
private void MethodA(TestAction action)
{
// I take a delegate!
}
private void MethodB(int a, int b)
using System;
using System.Threading.Tasks;
namespace asynctest
{
class Program
{
public async Task<int> AnAsyncMethod()
{
Console.WriteLine("Please wait");
function diceRoll(channelID, message) {
var number = 0;
const DICE_DEFAULT = 6;
if (message.length === 0 || isNaN(message)) {
number = roll(DICE_DEFAULT);
}
else if (message.indexOf("d") === -1 &&
message.indexOf("D") === -1) {
var sides = parseInt(message);
@Bocom
Bocom / main.c
Created September 3, 2015 19:34
typedef uint8_t u8;
typedef uint32_t u32;
typedef int32_t s32;
#define MAP_WIDTH 25
#define MAP_HEIGHT 15
#define MAP_SIZE_IN_BYTES MAP_WIDTH * MAP_HEIGHT * sizeof(u8)
typedef enum tile_type
{
@Bocom
Bocom / gist:89c737831b052468df93
Created January 28, 2015 14:01
Poor-man's breakpoint
function b()
{
echo '<pre>';
array_map(function($x) { var_dump($x); }, func_get_args());
echo '</pre>';
die;
}
%ALBUM ARTIST% - %DATE% - %ALBUM% - %DISCNUMBER% - %TRACKNUMBER% - %TITLE%
public class Game1 : MultithreadedGame
{
public GraphicsDeviceManager Graphics;
public DefaultMaterialSet ScreenMaterials;
Texture2D texture;
public Game1()
{
Graphics = new GraphicsDeviceManager(this)
using System.Collections;
using UnityEngine;
// Shakes the camera if placed on the camera's GameObject or a parent of the camera's GameObject.
// (Putting it on a parent of the camera stops it potentially interfering with other camera scripts).
public class CameraShake : MonoBehaviour {
// How fast the shaking magnitude reduces - this much per second
const float shakeFalloffSpeed = 2.0f;
// How quickly the camera shakes around
const float shakeSpeed = 20.0f;