Skip to content

Instantly share code, notes, and snippets.

View brandedoutcast's full-sized avatar
🔥

R2 brandedoutcast

🔥
View GitHub Profile
@brandedoutcast
brandedoutcast / Integer Stack Class.cs
Last active December 20, 2015 08:19
This is a C# code snippet to create Stack class without using Arrays. Its an integer stack class which can be easily modified to a generic class in order to support multiple data types.
class Stack
{
static int TotalCount;
static Element Minimum;
static Element Top;
public void Push(int Value)
{
Element Item;
@brandedoutcast
brandedoutcast / Avoid Multiple Inner Joins.sql
Last active December 28, 2015 02:49
Get Multiple Phones For Single Customer without using mutiple inner joins.
SELECT DISTINCT
STUFF((SELECT DISTINCT ',' + CP.Phone_Nbr
FROM Customer_Phone CP
WHERE CM.Cust_Nbr = CP.Cust_Nbr
FOR XML PATH(''), TYPE)
.value('.', 'NVARCHAR(MAX)'), 1, 2, '') Phones
FROM Customer_Phone CM where CM.Cust_Nbr = 321
@brandedoutcast
brandedoutcast / Calculate distance using Latitude & Longitude.sql
Last active August 29, 2015 14:01
Calculates distance between two points with their latitudes and longitudes.
SELECT l.Loc_Name, 6371.0E * ( 2.0E * asin(
case when 1.0E < (sqrt(square(sin(((RADIANS(CAST(36.5696 AS FLOAT)))-(RADIANS(CAST(l.Loc_Latitude AS FLOAT))))/2.0E))
+ (cos(RADIANS(CAST(l.Loc_Latitude AS FLOAT)))
* cos(RADIANS(CAST(36.5696 AS FLOAT)))
* square(sin(((RADIANS(CAST(87.1003 AS FLOAT)))
-(RADIANS(CAST(l.Loc_Longitude AS FLOAT))))/2.0E)))))
then 1.0E
else (sqrt(square(sin(((RADIANS(CAST(36.5696 AS FLOAT)))
-(RADIANS(CAST(l.Loc_Latitude AS FLOAT))))/2.0E))
+ (cos(RADIANS(CAST(l.Loc_Latitude AS FLOAT)))
@brandedoutcast
brandedoutcast / SyncSafe Integer Conversion.cs
Last active August 29, 2015 14:11
A class that contains methods to convert a normal integer from and to a sync-safe integer
static class SyncSafe
{
public int Encode(int normalInteger)
{
return EncodeOrDecode(normalInteger, Convertion.Encode);
}
public int Decode(int syncSafeInteger)
{
return EncodeOrDecode(syncSafeInteger, Convertion.Decode);
@brandedoutcast
brandedoutcast / Delete All Objects in SQL Server.sql
Last active August 29, 2015 14:22
Script to delete Functions, Stored Procedures, Views & Tables in a SQL Server Database
-- Delete All Functions
------------------------------------------------------------------------------------------------------
DECLARE @FUNCNAME VARCHAR(2500)
DECLARE FUNCCURSOR CURSOR FOR SELECT [NAME] FROM SYS.OBJECTS WHERE TYPE = 'FN'
OPEN FUNCCURSOR
FETCH NEXT FROM FUNCCURSOR INTO @FUNCNAME
WHILE @@FETCH_STATUS = 0
BEGIN
EXEC('DROP FUNCTION ' + @FUNCNAME)
FETCH NEXT FROM FUNCCURSOR INTO @FUNCNAME
@brandedoutcast
brandedoutcast / gulpfile.js
Last active December 31, 2015 16:11
Typical gulpfile.js template to start with for every web project
/// <binding ProjectOpened="default" />
// #region Dependencies
var gulp = require("gulp"),
sass = require("gulp-sass"),
coffee = require("gulp-coffee"),
prefix = require("gulp-autoprefixer"),
nano = require("gulp-cssnano"),
uglify = require("gulp-uglify"),
@brandedoutcast
brandedoutcast / Git Sparse Checkout.txt
Created October 15, 2015 18:53
How to do a sparse checkout in git
mkdir [RepoName]
git init
cd [RepoName]
git remote add -f origin [RepoURL]
git config core.sparseCheckout true
echo "some/dir/*" >> .git/info/sparse-checkout
echo "another/sub/tree/*" >> .git/info/sparse-checkout
git checkout master
or
@brandedoutcast
brandedoutcast / Update-npm.ps1
Last active December 10, 2015 02:19
Update npm to latest version on Windows
pushd ${env:ProgramFiles}\nodejs\node_modules\npm\
cp npmrc $env:userprofile\desktop
cd ../..
npm install npm@latest
mv $env:userprofile\desktop\npmrc npmrc -Force
popd
@brandedoutcast
brandedoutcast / Rename Database.sql
Created November 6, 2015 12:46
Rename a database by setting it into single user mode
USE master
ALTER DATABASE [DatabaseName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE [DatabaseName] MODIFY NAME = [NewDatabaseName]
ALTER DATABASE [NewDatabaseName] SET MULTI_USER
@brandedoutcast
brandedoutcast / BatchRename.ps1
Created February 20, 2016 18:44
Batch rename of files changing file extension #PowerShell
gci -Filter *.theme | % { ren $_.name ($_.name -replace ".theme", ".zip") }