Skip to content

Instantly share code, notes, and snippets.

@DCCoder90
DCCoder90 / Vector3SerializationSurrogate.cs
Created September 4, 2017 01:56
A serialization surrogate to allow the serialization of Vector3's with Unity
using UnityEngine;
using System.Runtime.Serialization;
public class Vector3SerializationSurrogate : ISerializationSurrogate {
// Method called to serialize a Vector3 object
public void GetObjectData(System.Object obj, SerializationInfo info, StreamingContext context) {
Vector3 v3 = (Vector3)obj;
info.AddValue("x", v3.x);
@DCCoder90
DCCoder90 / Hash.cs
Created September 15, 2017 13:42
Create MD5 hash from a string
using System;
using System.Text;
using System.Security.Cryptography;
static public string GetMd5Sum(string str){
Encoder enc = System.Text.Encoding.Unicode.GetEncoder();
byte[] unicodeText = new byte[str.Length * 2];
enc.GetBytes(str.ToCharArray(), 0, str.Length, unicodeText, 0, true);
@DCCoder90
DCCoder90 / StripTags.cs
Created September 17, 2017 19:35
Static Class to assist in stripping HTML tags from strings or Char arrays
using System;
using System.Text.RegularExpressions;
/// <summary>
/// Methods to remove HTML from strings.
/// </summary>
public static class StripTags
{
/// <summary>
/// Remove HTML from string with Regex.
@DCCoder90
DCCoder90 / jqueryselectchange.js
Last active November 21, 2017 20:32
jQuery Select change snippets
$(document).ready(function(){
//For static content
$('#selectID').change(function(){
//Do stuff!
});
//For dynamically loaded content:
$(document).on('change','#selectID',function(){
//Do stuff!
});
@DCCoder90
DCCoder90 / IsPrime.cs
Created November 24, 2017 15:50
Quick and dirty litter method to determine if a number is prime. Still has some issues that need to be worked out for int vs ulong
public static bool CalcIsPrime(dynamic number,out dynamic failure)
{
failure = 0;
if (number == 1) return false;
if (number == 2) return true;
if (number % 2 == 0) return false;
for (dynamic i = 2; i < (number/2); i++)
{
@DCCoder90
DCCoder90 / Imager.cs
Created November 24, 2017 23:45
Part of a larger project. This section temporarily maps a network drive.
public class Imager : IDisposable{
private string _persist = "NO";
private Process _networkMap;
public void Dispose()
{
_networkMap.Close();
}
@DCCoder90
DCCoder90 / slackreport.js
Created November 30, 2017 14:58
Report youtrack changes to slack with duedate and approval
// Thanks to Michael Rush for the original version of this rule (https://software-development.dfstudio.com/youtracks-new-javascript-workflows-make-slack-integration-a-breeze-d3275605d565)
// IMPORTANT: Use a valid Incoming Webhook from Slack. To get one, go to https://my.slack.com/services/new/incoming-webhook/
var SLACK_WEBHOOK_URL = 'WEBHOOKURL';
var entities = require('@jetbrains/youtrack-scripting-api/entities');
var http = require('@jetbrains/youtrack-scripting-api/http');
var workflow = require('@jetbrains/youtrack-scripting-api/workflow');
exports.rule = entities.Issue.onChange({
@DCCoder90
DCCoder90 / ForceNumeric.js
Created December 21, 2017 15:04
Forces only numeric input on selected field
$("selector").keydown(function (e) {
// backspace, delete, tab, escape, enter and .
if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
// Ctrl+A, Command+A
(e.keyCode === 65 && (e.ctrlKey === true || e.metaKey === true)) ||
// home, end, left, right, down, up
(e.keyCode >= 35 && e.keyCode <= 40)) {
return;
}
@DCCoder90
DCCoder90 / mysqlBackup.sh
Created January 12, 2018 14:43
Bash script to backup all databases
#!/bin/bash
mysqldump -u root -p[PASSWORD] --all-databases | gzip > /PATH/TO/STORE/BACKUP/mysqldb_`date +%F`.sql.gz
@DCCoder90
DCCoder90 / TerrainMath.cs
Created January 18, 2018 04:47
A collection of helpers for Terrain math with Unity
public static class TerrainMath{
/**
* Gets the XBase and width based on bounds input
* @param portalBounds The bounds of the Box collider to use
* @param terrainBounds The bounds of the terrain collider to use
* @return Vector2 Where X is the XBase and Y is the Width
* @static
*/
public static Vector2 GetXBaseAndWidth(Bounds portalBounds, Bounds terrainBounds){