Skip to content

Instantly share code, notes, and snippets.

@kkabdol
kkabdol / mouserotationlookat.cpp
Created January 15, 2019 14:09
Calculate look at vector after mouse scrolled
D3DXVECTOR3 CPR_Player::GetNewDirFromInput()
{
D3DXVECTOR3 newDir;
D3DXVECTOR2 deltaMousePos = ( GetMousePosition() - m_startMousePos );
deltaMousePos.x *= MOUSE_SENSITIVITY;
deltaMousePos.y *= MOUSE_SENSITIVITY;
deltaMousePos.x = ( abs( deltaMousePos.x ) > MOUSE_THRESHOLD ) ? deltaMousePos.x : 0.0f;
deltaMousePos.y = ( abs( deltaMousePos.y ) > MOUSE_THRESHOLD ) ? deltaMousePos.y : 0.0f;
deltaMousePos.y = CLAMP( deltaMousePos.y, D3DXToRadian( -89.9f ), D3DXToRadian( 89.9f ) );
@kkabdol
kkabdol / extractintegers.cpp
Created January 15, 2019 14:06
Extract all integers from string in C++
// https://www.geeksforgeeks.org/extract-integers-string-c/
vector<int> extractIntegerWords(string str)
{
vector<int> v;
stringstream ss;
/* Storing the whole string into string stream */
ss << str;
@kkabdol
kkabdol / greedy.cpp
Last active January 10, 2019 06:58
Activity Selection Problem
#include<bits/stdc++.h>
using namespace std;
// Greedy Algorithm
// https://en.wikipedia.org/wiki/Activity_selection_problem
struct Workshop
{
Workshop( int s, int d ) : start_time( s ), duration( d ), end_time( s + d ) {}
@kkabdol
kkabdol / bitarray.cpp
Last active January 10, 2019 22:25
The number of distinct integers in the created sequence
//
// a[0] = S (modulo 2^31)
// for i = 1 to N-1
// a[i] = a[i-1]*P+Q (modulo 2^31)
//
// https://www.hackerrank.com/challenges/bitset-1/forum/comments/138875
#include <algorithm>
#include <iostream>
@kkabdol
kkabdol / parameterpack.cpp
Last active January 10, 2019 11:19
Template Parameter Pack
// http://kevinushey.github.io/blog/2016/01/27/introduction-to-c++-variadic-templates/
// https://en.cppreference.com/w/cpp/language/parameter_pack
// https://www.hackerrank.com/challenges/cpp-variadics/problem
#include <iostream>
using namespace std;
template <bool a>
int reversed_binary_value()
{
@kkabdol
kkabdol / SWM.cpp
Last active January 9, 2019 12:56
Sliding Window Maximum
// https://www.geeksforgeeks.org/sliding-window-maximum-maximum-of-all-subarrays-of-size-k/
// A Dequeue (Double ended queue) based method for printing maixmum element of
// all subarrays of size k
void printKMax(int arr[], int n, int k)
{
// Create a Double Ended Queue, Qi that will store indexes of array elements
// The queue will store indexes of useful elements in every window and it will
// maintain decreasing order of values from front to rear in Qi, i.e.,
// arr[Qi.front[]] to arr[Qi.rear()] are sorted in decreasing order
@kkabdol
kkabdol / LCS.cpp
Created January 8, 2019 23:09
The longest common subsequence algorithm
// https://www.techiedelight.com/longest-common-subsequence/
int LCS( string X, string Y )
{
int m = X.length(), n = Y.length();
// lookup table stores solution to already computed sub-problems
// i.e. lookup[i][j] stores the length of LCS of substring
// X[0..i-1] and Y[0..j-1]
int lookup[m + 1][n + 1];
@kkabdol
kkabdol / shorten_audiofiles.py
Created December 18, 2018 00:39
Shortening audio files
import os
from pydub import AudioSegment // https://github.com/jiaaro/pydub
source_dir = "C:\Users\schoe\Desktop\Jukebox\source\\"
destination_dir = "C:\Users\schoe\Desktop\Jukebox\destination\\"
for file in os.listdir(source_dir):
milliseconds = 10*1000
print( "split \"" + file + "\" from " + source_dir + " into " + destination_dir + " by " + "{:,}".format( milliseconds / 1000 ) + " seconds." )
#define PI 3.14159265
degree = radian * 180 / PI;
@kkabdol
kkabdol / ue4_gist.cpp
Last active August 9, 2019 06:12
UE4 Gist
//////////////////////////////////////////////////////////////////////////////////////////
// Display the gamepad buttons in the editor with XBox or PS4 names
//////////////////////////////////////////////////////////////////////////////////////////
UEditorExperimentalSettings > TEnumAsByte < EConsoleForGamepadLabels::Type > ConsoleForGamepadLabels // Specify which console-specific nomenclature to use for gamepad label text
//////////////////////////////////////////////////////////////////////////////////////////
// Character Cheat-sheet
//////////////////////////////////////////////////////////////////////////////////////////