Skip to content

Instantly share code, notes, and snippets.

View emukupa's full-sized avatar

Edward Manda emukupa

  • Oklahoma City, Oklahoma, USA
View GitHub Profile
FROM gcc:7.3.0
RUN apt-get -qq update
RUN apt-get -qq upgrade
RUN apt-get -qq install cmake
RUN apt-get -qq install libboost-all-dev=1.62.0.1
RUN apt-get -qq install build-essential libtcmalloc-minimal4 && \
ln -s /usr/lib/libtcmalloc_minimal.so.4 /usr/lib/libtcmalloc_minimal.so
function shuffle() {
// Fisher-Yates shuffle algorithm
for (let i = this.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
const temp = this[j];
this[j] = this[i];
this[i] = temp;
}
return this;
}
import mersenneSequence from "./mersenne_sequence";
import isPrime from "./isPrime";
const max: number = 100;
// warning: this takes a long time to run?? you have been warned!!
for (let n = 1; n < max; n++) {
let primeCount: number = 0;
const mList: number[] = mersenneSequence(n);
const mersenneSequenceNumber = x => 2 * x + 1; // f(x) = 2x + 1
function mersenneSequence(upTo = 10) {
const list = [0]; // init with the first number
// make the rest using the previous number in the list
for (let i = 0; i < upTo; i++) {
list.push(mersenneSequenceNumber(list[i]));
}
const rgbColor = () => Math.floor(Math.random() * 256); // numbers betweer 0 - 255
// rgba === red, green, blue and alpha
// rgba examples: white rgba(255, 255, 255, 1), black rgba(0, 0, 0, 1)... etc
const randomRGBColor = (alpha = 1) => `rgba(${rgbColor()}, ${rgbColor()}, ${rgbColor()}, ${alpha})`;
// RESULTS
// rgba(204, 36, 145, 1), all values are random between 0 - 255, last value is definitely 1
console.log(randomColor());
// rgba(219, 106, 175, 0.5), all values are random between 0 - 255, last value is definitely 0.5
const sum = (x, y) => {
if(Number(x) && Number(y)){
let result = x;
while(y != 0){
// AND to get carry
const carry = result & y;
// XOR to get new result
result = result ^ y;
const Counter = {
count: 0,
incrementFunc: function(){
this.count++;
},
incrementArrowFunc: () => {
//this.count++; does nothing
Counter.count++;
},
getCountFunc: function(){
@emukupa
emukupa / operate.js
Created November 28, 2019 19:31
operate function lets you define your own function and args
function operate(doOperation = () => 'Think of something creative.', ...args){
// doOperation has to be a function
if (typeof doOperation != 'function') {
return 'First argument must be a function.';
}
if(args.length === 0){
return doOperation();
} else if( args.length === 1){
return doOperation(args[0]);
@emukupa
emukupa / binary-search-tree-cpp.cpp
Created January 30, 2019 12:03 — forked from mgechev/binary-search-tree-cpp.cpp
Simple implementation of binary search tree in C++.
#include <iostream>
#include <math.h>
using namespace std;
template <class T>
struct Node {
T value;
Node *left;
Node *right;
@emukupa
emukupa / docker-help.md
Created December 20, 2018 06:22 — forked from bradtraversy/docker-help.md
Docker Commands, Help & Tips

Docker Commands, Help & Tips

Show commands & management commands

$ docker

Docker version info