Skip to content

Instantly share code, notes, and snippets.

Avatar

Chukwuerika Dike andela-cdike

View GitHub Profile
View classic-editor.js
const { Component } = wp.element;
import { __, _x } from '@wordpress/i18n';
const { BACKSPACE, DELETE, F10 } = wp.keycodes;
function isTmceEmpty(editor) {
// When tinyMce is empty the content seems to be:
// <p><br data-mce-bogus="1"></p>
// avoid expensive checks for large documents
const body = editor.getBody();
View insertionsort.py
def insertion_sort(alist):
marker = 1
while marker < len(alist):
current = alist[marker]
second_marker = marker - 1
while current < alist[second_marker] and second_marker >= 0:
alist[second_marker + 1] = alist[second_marker]
second_marker -= 1
alist[second_marker + 1] = current
View mergesort.py
def merge_sort(alist):
if len(alist) > 1:
mid = len(alist) // 2
lefthalf = alist[:mid]
righthalf = alist[mid:]
merge_sort(lefthalf)
merge_sort(righthalf)
i = j = k = 0
View quicksort.py
def quicksort(alist):
if len(alist) < 2:
return alist
else:
pivot = alist[0]
less = [num for num in alist[1:] if num <= pivot]
greater = [num for num in alist[1:] if num > pivot]
return quicksort(less) + [pivot] + quicksort(greater)
View heapsort.py
"""I use arrays to implement the heap and array content start at index 1"""
def max_heapify(array, i):
left = 2 * i
right = 2 * i + 1
N = len(array) - 1
if left <= N and array[left] > array[i]:
largest = left
else:
largest = i
View astar.py
def heauristic(a, b):
(x1, y1) = a
(x2, y2) = b
return abs(x1 - x2) + abs(y1 - y2)
def a_star_search(graph, start, goal):
frontier = PriorityQueue()
frontier.put(start, 0)
came_from = {}
View dijkstra_search.py
def dijkstra_search(graph, start, goal):
frontier = PriorityQueue()
frontier.put(start, 0)
came_from = {}
cost_so_far = {}
came_from[start] = None
cost_so_far[start] = 0
while not frontier.empty():
current = frontier.get()[1]
View PostContent.test.js
import React from 'react';
import { shallow } from 'enzyme';
import {
PostMediaContainer,
PostTextContainer,
} from './components';
import PostContent from './PostContent';
View PostContent.js
import React from 'react';
import getUrls from 'get-urls';
import linkifyHtml from 'linkifyjs/html';
import PropTypes from 'prop-types';
import {
PostMediaContainer,
PostTextContainer,
} from './components';
View PostContent.test.js
import React from 'react';
import { mount, shallow } from 'enzyme';
import {
PostMediaContainer,
PostTextContainer,
} from './components';
import PostContent from './PostContent';
You can’t perform that action at this time.