Skip to content

Instantly share code, notes, and snippets.

greathmaster

Block or report user

Report or block greathmaster

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@greathmaster
greathmaster / 2d-array-mapping.js
Created Oct 11, 2019
Mapping over a 2D array in JS.
View 2d-array-mapping.js
/*
Mapping over a 2D array in JS.
Taken from: https://stackoverflow.com/questions/45659734/how-to-use-array-map-with-a-2-dimensional-array
*/
arr.map( function( row ) {
return row.map( function( cell ) {
return foo( cell );
} );
} )
View 2d-array-fill-initialization.js
//Fill/initialize a 2D JS array
//From: https://www.quora.com/In-JavaScript-how-do-you-create-an-empty-2D-array
var twoDArray = Array(2).fill(null).map(()=>Array(2).fill(null));
@greathmaster
greathmaster / binary-search.js
Last active Sep 18, 2019
Binary Search in JS
View binary-search.js
//Iterative Solution
var bsearchIter = function(nums, target) {
let [left, right] = [0, nums.length-1];
while(left <= right) {
let mid = Math.floor((left + right)/2);
if(target < nums[mid]) {
right = mid-1;
} else if(target > nums[mid]){
left = mid+1;
}else {
@greathmaster
greathmaster / get-column-of-2D-array.js
Created Aug 7, 2019
Get the column of a 2D array/matrix in JS
View get-column-of-2D-array.js
//Get the column of a 2D array in JS
//Taken from https://stackoverflow.com/questions/7848004/get-column-from-a-two-dimensional-array
const arrayColumn = (arr, n) => arr.map(x => x[n]);
const twoDimensionalArray = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
];
@greathmaster
greathmaster / heap.js
Last active Jul 28, 2019
Heap implementation in JS. Defaults to Min Heap. Inherit and override compare to implement a Max Heap
View heap.js
/*
Heap implementation in JS.
Description of Heap:
https://en.wikipedia.org/wiki/Heap_(data_structure)
Defaults to MinHeap. Extend class and override
compare(a, b) to implement MaxHeap.
*/
@greathmaster
greathmaster / Trie.js
Created Jul 20, 2019 — forked from tpae/Trie.js
Trie.js - super simple JavaScript implementation
View Trie.js
// Trie.js - super simple JS implementation
// https://en.wikipedia.org/wiki/Trie
// -----------------------------------------
// we start with the TrieNode
function TrieNode(key) {
// the "key" value will be the character in sequence
this.key = key;
@greathmaster
greathmaster / pmpro-sequential-member-numbers-3.php
Created May 24, 2019
PMPro Sequential Member Numbers 3: Member numbers are automatically increased from the value set for $starting_member_number after each member registration
View pmpro-sequential-member-numbers-3.php
/*
Sequential Member Numbers
* Member numbers are automatically increased from the value set for $starting_member_number after each member registration
* Existing members already in the system will not receive a membership number
*/
//Generate member_number when a user is registered.
function generate_member_number($user_id)
{
$starting_member_number = 100000;
View pmpro-sequential-member-number-2.php
/*
Sequential Member Numbers
* Member numbers are automatically increased from the value set for $starting_member_number after each member registration
* Existing members already in the system will not receive a membership number
*/
//Generate member_number when a user is registered.
function generate_member_number($user_id, $decrement = false)
{
$starting_member_number = 100000;
@greathmaster
greathmaster / pmpro-member-directory-hide-admin-created-new-users-automatically.php
Created May 22, 2019
Set flag to hide members from the directory upon new user creation by an admin
View pmpro-member-directory-hide-admin-created-new-users-automatically.php
/*Set flag to hide members from the directory upon new user creation by an admin*/
function pmpromd_set_visibility_to_hidden_edit_user_created_user ($user_id, $notify)
{
update_user_meta( $user_id, 'pmpromd_hide_directory', true );
}
add_action('edit_user_created_user', 'pmpromd_set_visibility_to_hidden_edit_user_created_user', 10, 2);
@greathmaster
greathmaster / pmpro-load-different-css-file-depending-on-membership-level.php
Last active May 16, 2019
Load a different CSS file depending on the membership level
View pmpro-load-different-css-file-depending-on-membership-level.php
//Originally coded by user Marc1205 in private support forum:
// https://www.paidmembershipspro.com/forums/topic/different-stylesheets-for-user-levels/
function pmproc_preheader() {
if(pmpro_hasMembershipLevel('your_membership_name')) {
wp_enqueue_style( 'basse', get_stylesheet_directory_uri().'/mfk-dev/assets/css/basse.css' );
}
if(pmpro_hasMembershipLevel('your_membership_name')) {
You can’t perform that action at this time.