Skip to content

Instantly share code, notes, and snippets.

View N02870941's full-sized avatar
🎯
Focusing

N02870941

🎯
Focusing
View GitHub Profile
@N02870941
N02870941 / video.sh
Last active May 15, 2019 02:42
Download a list of RTSP streams via URL to files
# README:
#
# Run this script as follows:
#
# ./video.sh urls.txt videos
#
# Where urls.txt is a list of RTSP links
# and videos is the directory that you would
# like to save the downloaded videos to. If
# the designated directory does not exist, it
@N02870941
N02870941 / Threads.java
Last active February 15, 2019 09:37
A simple Java class with a one-liner that utilizes Java 8 lambdas to concisely demonstrate how to use threads and accomplish concurrency in Java.
import java.util.stream.IntStream;
class Threads {
public static void main(String... args) {
IntStream
.range(0, 10)
.mapToObj(i -> new Thread(() -> System.out.println(Thread.currentThread().getName())))
.forEach(thread -> thread.start());
import java.util.concurrent.ThreadLocalRandom;
import java.util.Arrays;
/**
* Quicksort implementation that counts that
* number of comparisons required to perform the sort.
*
* @author Jabari Dash
*/
public class QuickSort {
@N02870941
N02870941 / sorting.py
Created September 12, 2018 08:54
A few sorting algorithms in Python
import math
import random
#-------------------------------------------------------------------------------
'''
Default comparator that sorts
numeric values in their natural order.
'''
def comparator(one, two):
/**
* Sorts an array of values. An optional 2 parameter comparator function is available
* to specify ordering. If no comparator is supplied, then the values will be sorted
* based on their primitive values via the Object.prototype.valueOf() function.
*/
function sort(array, comparator = (a, b) => a.valueOf() - b.valueOf()) {
quicksort(array, 0, array.length-1, comparator)
}
//------------------------------------------------------------------------------
@N02870941
N02870941 / Contains.java
Created August 3, 2018 09:05
Various ways to check is a 2-dimensional ArrayList contains a specified value
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Collectors;
public class Contains {
@N02870941
N02870941 / bst.go
Created June 29, 2018 00:11
Binary Search Tree in GoLang
package main
import "fmt"
import "strconv"
//------------------------------------------------------------------------------
type Node struct {
data int
@N02870941
N02870941 / Timsort
Created May 1, 2018 05:35 — forked from nandajavarma/Timsort
Timsort implementation using Python
#!/usr/lib/python
# -*- coding: utf-8 -*-
#
# This is a re-implementation of Python's timsort in Python
# itself. This is purely for learning purposes. :)
# References: [
# https://en.wikipedia.org/wiki/Timsort,
# http://wiki.c2.com/?TimSort
# ]
#
@N02870941
N02870941 / ToBinary.java
Last active September 12, 2018 09:16
Convert decimal integer to binary string
public class ToBinary {
/**
* Converts a positive integer to binary.
*
* @param decimal Decimal number.
* @return Binary string.
*/
public static String binary(int decimal) {
@N02870941
N02870941 / back_forward.js
Created December 13, 2017 19:47 — forked from sstephenson/back_forward.js
How to detect whether a hash change came from the Back or Forward button
var detectBackOrForward = function(onBack, onForward) {
hashHistory = [window.location.hash];
historyLength = window.history.length;
return function() {
var hash = window.location.hash, length = window.history.length;
if (hashHistory.length && historyLength == length) {
if (hashHistory[hashHistory.length - 2] == hash) {
hashHistory = hashHistory.slice(0, -1);
onBack();