Skip to content

Instantly share code, notes, and snippets.

View CraftedPvP's full-sized avatar
♥️

CraftedPvP

♥️
View GitHub Profile
@CraftedPvP
CraftedPvP / generate-pushid.js
Created November 1, 2022 11:46 — forked from mikelehen/generate-pushid.js
JavaScript code for generating Firebase Push IDs
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
// in Start() of "(Unity Project path)\Library\PackageCache\[email protected]\Runtime\2D\ShadowCaster2D.cs"
// have replace it with this:
private void Awake() {
if(m_ApplyToSortingLayers == null)
m_ApplyToSortingLayers = SetDefaultSortingLayers();
Bounds bounds = new Bounds(transform.position, Vector3.one);
Renderer renderer = GetComponent<Renderer>();
if (renderer != null)
{
@CraftedPvP
CraftedPvP / Visual Studio Cache Remover.gitignore
Created October 18, 2019 03:36
Removes the usual cache of Visual studio's projects so you don't have to worry about uploading crap into your git repository
# prevents local database from being uploaded
*.mdf
# prevents addition of .txt files
*.txt
# trash
**/.trash/
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
@CraftedPvP
CraftedPvP / Glut Mouse Events.cpp
Created September 14, 2019 11:29
A C++ template for Glut Mouse button events
int lastMouseBtnStateLeft = GLUT_UP; // last left mouse buttons state
int lastMouseBtnStateRight = GLUT_UP; // last right mouse buttons state
void processMouse(int button, int state1, int x, int y){
if (button == GLUT_LEFT_BUTTON) {
// decode and handle the mouse events by type
if ((lastMouseBtnStateLeft == GLUT_UP )&&(state1 == GLUT_DOWN)) // mouse down (click)
{
// here do your stuff
}
if ((lastMouseBtnStateLeft == GLUT_DOWN)&&(state1 == GLUT_DOWN)) // mouse move while clicked
@CraftedPvP
CraftedPvP / CraftedStringConverter.h
Created July 15, 2019 03:58
Created because of annoying data types that could have just contained the necessary data type conversion. Also contains some debugging and some helpful string to char conversions and vice-versa
#ifndef CRAFTEDSTRINGCONVERTER_H
#define CRAFTEDSTRINGCONVERTER_H
#include <codecvt> // converter
#include <string>
#include <Windows.h>
#include <tchar.h> // WCHAR and wchar_t
#include <stdlib.h> // mbstowcs_s
#include <cstring> // strlen
#include <iostream> // cout endl
using std::string; using std::wstring;
@CraftedPvP
CraftedPvP / Setting an image through HttpURLConnection.java
Created November 6, 2017 12:50
Setting an image into an ImageView through the use of BitmapFactory and HttpURLConnection. Tested on Android.
/**
* This function sets the image into the imageView.
*/
public void setBitmapFromNetwork(){
Runnable runnable = new Runnable() {
Bitmap bitmap = null;
@Override
public void run() {
@CraftedPvP
CraftedPvP / PasswordInput - Asterisks.cpp
Created June 28, 2017 12:07
This allows the user to hide his/her password and displaying them as asterisks. This code runs on Windows operating system.
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
class PasswordInput
{
private:
string password; /* The string to store the password */
@CraftedPvP
CraftedPvP / PasswordInput - Invisible.cpp
Created June 28, 2017 11:44
This makes the user input text but it will not be shown in the screen. This code can run on both Windows and *nix operating systems.
//original source: https://stackoverflow.com/questions/1413445/reading-a-password-from-stdcin
#ifdef WIN32
#include <windows.h>
#else
#include <termios.h>
#include <unistd.h>
#endif
void SetStdinEcho(bool enable = true)
{
@CraftedPvP
CraftedPvP / Sorting algorithms.cpp
Last active June 1, 2017 11:26
Contains Insertion, Quick, and Bubble Sorting snippets for C++. Links provided for further description of what each sorting algorithm does. Hope this helps :)
//
//---Insertion Sort - Sorts the data by pairs then checks j from those behind it---//
//--- Link: http://cforbeginners.com/insertionsort.html ---//
//
void insertion_sort (int arr[], int length){
int j, temp;
for (int i = 1; i < length; i++){
j = i;
while (j > 0 && arr[j] < arr[j-1]){
temp = arr[j];