Skip to content

Instantly share code, notes, and snippets.

View coderodde's full-sized avatar

Rodion Efremov coderodde

View GitHub Profile
@coderodde
coderodde / Arrays.java
Last active June 17, 2019 05:21
Gist for net.coderodde.util.Arrays.sort(byte[])
package net.coderodde.util;
import java.util.Random;
/**
* This class contains static methods for sorting {@code byte} arrays.
*
* @author Rodion "rodde" Efremov
* @version 1.6 (Apr 24, 2019)
*/
package net.coderodde.util;
import java.util.Random;
/**
* This class contains a method for converting {@code long} values to strings.
*
* @author Rodion "rodde" Efremov
* @version 1.6 (May 13, 2019)
*/
@coderodde
coderodde / semaphore_impl.cpp
Created January 11, 2019 14:18
Windows port for a semaphore data type.
#include "semaphore_impl.h"
#include <windows.h>
static const char* CLASS = "net/coderodde/util/concurrent/WindowsSemaphoreImpl";
static const char* FIELD = "semaphoreHandle";
static HANDLE get_semaphore_handle(JNIEnv* env, jobject obj)
{
jclass clazz = env->FindClass(CLASS);
jfieldID fid = env->GetFieldID(clazz, FIELD, "J");
@coderodde
coderodde / dt_tag_entry.cpp
Created November 22, 2018 06:22
Directory tagger.
#include "dt_tag_entry.hpp"
#include <string>
#include <utility>
namespace net {
namespace coderodde {
namespace dt2 {
TagEntry::TagEntry(std::string const& tag,
std::string const& directory)
@coderodde
coderodde / war.py
Last active June 9, 2018 15:09
Researching war scheduling algorithms.
import copy
import random
import time
from heapq import heappush, heappop
class Country:
def __init__(self, name, resources):
self.name = name
@coderodde
coderodde / main.c
Last active September 13, 2024 11:17
Parallel for loop construct in C - follow-up
#include "parallel_for.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#if defined(__APPLE__) || defined(__linux__)
#define POSIX
#endif
#if defined(POSIX)
@coderodde
coderodde / main.c
Last active January 21, 2018 17:20
Parallel for loop construct for C
#include "parallel_for.h"
#include <stdio.h>
#include <stdlib.h>
#if defined(__APPLE__)
#include <sys/time.h>
#elif defined(__linux__)
#include <sys/time.h>
#elif defined(_WIN32)
#include <windows.h>
#else
@coderodde
coderodde / Benchmark.java
Created December 1, 2017 08:49
CR for boundary entries.
package net.coderodde.boundaries;
import java.util.ArrayList;
import java.util.Random;
/**
* This class implements a benchmark for the boundary algorithms.
*
* @author Rodion "rodde" Efremov
* @version 1.6 (Dec 1, 2017)
@coderodde
coderodde / IntegerPatternMatching.java
Created October 31, 2017 14:35
IntegerPatternMatching.java
package net.coderodde.util;
import java.util.Random;
public class IntegerPatternMatching {
public static int getSubArrayIndex(int[] parentArr, int[] subArr) {
boolean found = false;
for (int i = 0; i <= parentArr.length - subArr.length; i++) {
if (parentArr[i] == subArr[0]) {
@coderodde
coderodde / TupleIterable.java
Created October 6, 2017 19:11
Tuple iterator in Java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Objects;
public final class TupleIterable<T> implements Iterable<List<T>> {