Skip to content

Instantly share code, notes, and snippets.

View wizo06's full-sized avatar

wizo wizo06

View GitHub Profile
@wizo06
wizo06 / nginx101.md
Last active February 25, 2021 23:29
@wizo06
wizo06 / collatz.cpp
Last active June 22, 2018 00:02
To run: Compile and "./collatz <integer>". Collatz Conjecture in C++. Left column is the number of steps to get to 1.
// Warning: maximum value for a variable of type int: 2,147,483,647
#include <stdio.h>
int main(int argc, char *argv[]){
if(argc == 2){
int x = atoi(argv[1]); int n = 0; printf("%i %i\n",n,x);
if(x < 1){
exit(1);
}
else{
while(x != 1){
@wizo06
wizo06 / collatz.js
Last active June 22, 2018 00:06
To run: "node collatz.js <integer>". Collatz Conjecture in Javascript. Left column is the number of steps to get to 1.
// Warning: maximum value for a variable of type Number (no bitwise or shift operators allowed): 9,007,199,254,740,991
let x = parseInt(process.argv[2]);
if(isNaN(x)) process.exit(1);
else{
if(x < 1){
process.exit(1);
}
else{
let n = 0; console.log(`${n} ${x}`);
while (x !== 1){
@wizo06
wizo06 / getLongestSubstring.js
Last active June 9, 2018 22:30
To run: "node getLongestSubstring.js <string>". Get longest substring in alphabetical order from a string. Javascript-specific methods were avoided as much as possible. Complexity is O(n).
/*
* Assume s is a string of lower case characters.
*
* Write a program that prints the longest substring of s
* in which the letters occur in alphabetical order.
*
* For example, if s = 'azcbobobegghakl', then your program should print
* "Longest substring in alphabetical order is: beggh"
*
* In the case of ties, print the first substring.
@wizo06
wizo06 / asyncJS-test
Created May 19, 2018 15:19
snippet to test if a function has async calls inside it
var work = process._getActiveHandles().length + process._getActiveRequests().length;
foo();
var newWork = (process._getActiveHandles().length + process._getActiveRequests().length) - work;
if(newWork > 0) {
console.log("asynchronous work took place.");
}