Skip to content

Instantly share code, notes, and snippets.

@jbbn
jbbn / anagrams.alternate.js
Last active December 11, 2023 22:22
BairesDev Anagrams
const fs = require('fs')
const { log, splitByBreakline } = require('./utils')
const { getAnagramsFromWordsWith } = require('./utils.anagrams')
const logAnagramsFromFile = (filepath, target) => {
const getAnagramsForTargetFromWords = getAnagramsFromWordsWith(target)
// splitByBreakline | getAnagramsForTargetFromWords | log
const handleFileCallback = (err, words) => log(
getAnagramsForTargetFromWords(
function buildMaxHeap(array) {
var i;
i = array.length / 2 - 1;
i = Math.floor(i);
// Build a max heap out of
// all array elements passed in.
while (i >= 0) {
heapify(array, i, array.length);
i -= 1;
@Aneurysm9
Aneurysm9 / .tmux.conf
Created June 28, 2017 21:22
Basic screen-like tmux config with vim-like movements
# Set the prefix to ^A.
unbind C-b
set -g prefix ^A
bind a send-prefix
# Bind appropriate commands similar to screen.
# lockscreen ^X x
unbind ^X
bind ^X lock-server
unbind x
@thomasdarimont
thomasdarimont / KeycloakAdminClientExample.java
Last active April 30, 2024 22:18
Using Keycloak Admin Client to create user with roles (Realm and Client level)
package demo.plain;
import org.keycloak.OAuth2Constants;
import org.keycloak.admin.client.CreatedResponseUtil;
import org.keycloak.admin.client.Keycloak;
import org.keycloak.admin.client.KeycloakBuilder;
import org.keycloak.admin.client.resource.RealmResource;
import org.keycloak.admin.client.resource.UserResource;
import org.keycloak.admin.client.resource.UsersResource;
import org.keycloak.representations.idm.ClientRepresentation;
// C++ includes used for precompiling -*- C++ -*-
// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
@dario2994
dario2994 / generate_hcn.py
Last active May 4, 2024 16:39
Highly composite numbers list
#!/usr/bin/env python3
# This program prints all hcn (highly composite numbers) <= MAXN (=10**18)
#
# The value of MAXN can be changed arbitrarily. When MAXN = 10**100, the
# program needs less than one second to generate the list of hcn.
from math import log
MAXN = 10**18
@loderunner
loderunner / 01-mac-profiling.md
Last active March 17, 2024 04:13
Profiling an application in Mac OS X

Profiling an application in Mac OS X

Finding which process to profile

If your system is running slowly, perhaps a process is using too much CPU time and won't let other processes run smoothly. To find out which processes are taking up a lot of CPU time, you can use Apple's Activity Monitor.

The CPU pane shows how processes are affecting CPU (processor) activity:

@pfigue
pfigue / clock_gettime.c
Created April 23, 2015 07:54
Example of using libC clock_gettime() and clock_getres() functions.
#include <stdio.h>
#include <time.h>
int main(int argc, char **argv)
{
int result;
struct timespec tp;
clockid_t clk_id;
@m00nlight
m00nlight / gist:1f226777a49cfc40ed8f
Last active March 7, 2022 12:24
Python range minimum query
import sys
import itertools
class RMQ:
def __init__(self, n):
self.sz = 1
self.inf = (1 << 31) - 1
while self.sz <= n: self.sz = self.sz << 1
self.dat = [self.inf] * (2 * self.sz - 1)
@nmpowell
nmpowell / word_frequency.py
Last active December 22, 2022 06:23
Count words in a text file, sort by frequency, and generate a histogram of the top N
#!/usr/bin/python
"""Python script to create a histogram of words in a text file.
Usage: python word_frequency.py -f "/path/to/file.txt" -n 200
Specify the path to the text file as above. Manually specify the top N words to report (default 100).
Text file can contain punctuation, new lines, etc., but special characters aren't handled well.