Skip to content

Instantly share code, notes, and snippets.

@ilearnio
ilearnio / binary-search.c
Last active May 13, 2016 20:06
Binary search realization in C (simplest and probably fastest)
#include <math.h>
#include <stdbool.h>
bool binarySearch(int value, int values[], int n)
{
// Memorize the offset of a half rather then create an array on each iteration
int offset = 0;
int divider = n;
while (divider > 0) {
divider = round((divider + 1) / 2); // round up
{
"bootstrapped": true,
"in_process_packages":
[
],
"installed_packages":
[
"AutoBackups",
"AutoFileName",
"Babel",
@ilearnio
ilearnio / list-module-children.js
Last active March 18, 2016 13:53
List children imported modules (paths) of a module
function listModuleChildren (parent_path) {
const parent_mod = require.cache[parent_path]
let children = []
;(function run (mod) {
if (mod.children.length) {
for (let i = 0; i < mod.children.length; i++) {
const id = mod.children[i].id
if (!children.includes(id)) {
@ilearnio
ilearnio / index.js
Last active December 13, 2015 17:17
fixJSON function. Removes comments and trailing commas from JSON
/**
* Removes comments and trailing commas from JSON
*/
function fixJSON(str) {
return str
// remove comments
.replace(/\/(?:\*{2,}\s[\s\S]+?|\*[^\*]+?)\*\/|([\s;])+\/\/.*$/gm, '')
// remove trailing commas
.replace(/,+\s*(\}|\])/g, '$1');
}