Skip to content

Instantly share code, notes, and snippets.

View morbidcamel101's full-sized avatar
🎯
Focusing

MorbidCamel morbidcamel101

🎯
Focusing
View GitHub Profile
@morbidcamel101
morbidcamel101 / ISO3166-1.alpha2.json
Created August 4, 2020 22:16 — forked from ssskip/ISO3166-1.alpha2.json
json of country codes (ISO 3166-1 alpha-2) and corresponding names
{
"AF": "Afghanistan",
"AX": "Aland Islands",
"AL": "Albania",
"DZ": "Algeria",
"AS": "American Samoa",
"AD": "Andorra",
"AO": "Angola",
"AI": "Anguilla",
"AQ": "Antarctica",
@morbidcamel101
morbidcamel101 / FastRandom.cs
Created January 29, 2020 19:12
Simple random number generator. We don't need great randomness, we just need a little and for it to be fast.
internal struct FastRandom // xorshift prng
{
private uint _w, _x, _y, _z;
public FastRandom(int seed)
{
_x = (uint)seed;
_w = 88675123;
_y = 362436069;
_z = 521288629;
@morbidcamel101
morbidcamel101 / GenNumberRange.sql
Created June 6, 2019 18:40
Generate a range of numbers for insersion SQL
DECLARE
@X INT = 1
,@Y INT = 1000
SELECT ones.n + 10*tens.n + 100*hundreds.n + 1000*thousands.n
FROM (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) ones(n),
(VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) tens(n),
(VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) hundreds(n),
(VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) thousands(n)
;WITH CTE AS(
SELECT field_to_identify_duplicate,
RN = ROW_NUMBER()OVER(PARTITION BY field_to_identify_duplicate ORDER BY field_to_identify_duplicate)
FROM table_with_duplicates
)
DELETE FROM CTE WHERE RN > 1
@morbidcamel101
morbidcamel101 / GenCodeFromName.sql
Last active May 29, 2019 16:26
Generate a Code from a persons FullName in SQL
SELECT
C.[Name]
,C.Code + CAST(C.SEQ AS NVARCHAR(2)) AS Code
FROM
(
SELECT
O.*
,ROW_NUMBER() OVER(PARTITION BY dbo.udf_ExtractUpper([Name]) ORDER BY [Name] ASC) SEQ
FROM
(SELECT
@morbidcamel101
morbidcamel101 / MoveCamera.cs
Created January 14, 2018 21:29 — forked from JISyed/MoveCamera.cs
Camera movement script in Unity3D. Supports rotating, panning, and zooming. Attach to the main camera. Tutorial explaining code: http://jibransyed.wordpress.com/2013/02/22/rotating-panning-and-zooming-a-camera-in-unity/
// Credit to damien_oconnell from http://forum.unity3d.com/threads/39513-Click-drag-camera-movement
// for using the mouse displacement for calculating the amount of camera movement and panning code.
using UnityEngine;
using System.Collections;
public class MoveCamera : MonoBehaviour
{
//
// VARIABLES
@morbidcamel101
morbidcamel101 / styleextension.js
Created March 16, 2017 16:18
JQuery style with !important
(function($) {
if ($.fn.style) {
return;
}
// Escape regex chars with \
var escape = function(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
};
@morbidcamel101
morbidcamel101 / endswith.js
Created March 6, 2017 21:31
End with string extension
String.prototype.endsWith = function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
@morbidcamel101
morbidcamel101 / urlobject.js
Created February 22, 2017 15:05 — forked from aymanfarhat/urlobject.js
JS utility function that: - Breaks down url to an object with accessible properties: protocol, parameters object, host, hash, etc... - Converts url parameters to key/value pairs - Convert parameter numeric values to their base types instead of strings - Store multiple values of a parameter in an array - Unescape parameter values
function urlObject(options) {
"use strict";
/*global window, document*/
var url_search_arr,
option_key,
i,
urlObj,
get_param,
key,
@morbidcamel101
morbidcamel101 / Guard.cs
Last active February 9, 2017 14:41
Common Guard Clauses
public static class Guard
{
#region ArgumentNotNull
/// <summary>
/// Checks an argument to ensure it isn't null
/// </summary>
/// <param name="argumentValue">The argument value to check.</param>
/// <param name="argumentName">The name of the argument.</param>
public static void ArgumentNotNull(object argumentValue, string argumentName)
{