Skip to content

Instantly share code, notes, and snippets.

View rustyconover's full-sized avatar
🕶️
The future is so bright.

Rusty Conover rustyconover

🕶️
The future is so bright.
View GitHub Profile
@rustyconover
rustyconover / load-and-analyze-samples.js
Created January 12, 2021 18:17
Load and Analyze PCM samples
// Keep an array of indexes of loud samples.
const loud_indexes = [0];
{
const pcm_data = fs.readFileSync(pcm_output, { encoding: null });
const pcm_values = new Int16Array(pcm_data.buffer);
// The first segment may be longer than normal due to Icecast
// buffering.
if (pcm_values.length > (window_length / 1000) * sample_rate * 1.2) {
return;
@rustyconover
rustyconover / listen.js
Created January 12, 2021 16:12
Listen to Icecast Stream
function listenToStream(stream_id: number, description: string) {
const options = {
hostname: 'broadcastify.cdnstream1.com',
port: 443,
headers: {
'sec-ch-ua-mobile': '?0',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
'Accept': '*/*',
'Origin': 'https://www.broadcastify.com',
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rustyconover
rustyconover / linked-list-shared.py
Created May 7, 2015 15:59
Find the first shared node between two linked lists
from operator import itemgetter
class ListNode:
def __init__(self, value):
self.value = value
# Append a node to this list node by setting the next property
def append(self, node):
self.next = node
@rustyconover
rustyconover / Collatz.java
Created May 6, 2015 02:11
Collate sequence length in Java
public class Collatz {
private static int count_until_1(long n) {
int count = 0;
while(n != 1) {
if(n % 2 == 0) {
n /= 2;
} else {
n = (n * 3) + 1;
}
count++;
@rustyconover
rustyconover / collatz-sequence.js
Created May 5, 2015 21:44
Collatz sequence in Javascript
'use strict';
function collatz_count_until_1(n) {
var count = 0;
while(n !== 1) {
if(n % 2 === 0) {
n /= 2;
} else {
n = (3 * n) + 1;
}
count++;
@rustyconover
rustyconover / collatz-sequence.c
Created May 5, 2015 21:33
Collatz sequence in C
#include <stdio.h>
int collatz_count_until_1(unsigned int n) {
int count = 0;
while(n != 1) {
if(n % 2 == 0) {
n /= 2;
} else {
n = (3 * n) + 1;
}
@rustyconover
rustyconover / collatz-sequence.pl
Created May 5, 2015 21:01
Collate sequence counter for Perl
use strict;
use warnings;
sub collatz_count_until_1 {
my $n = shift;
my $count = 0;
while ($n != 1) {
$n = (($n % 2 == 0) ? ($n/2) : (($n*3) + 1));
$count++;
}
@rustyconover
rustyconover / collatz-sequence.py
Created May 5, 2015 20:51
Find the number that results in the longest set of terms when using the Collatz sequence
def collatz_count_until_1(n):
count = 0
while n != 1:
if n % 2 == 0:
n = n / 2
else:
n = (3 * n) + 1
count += 1
return count
@rustyconover
rustyconover / gist:b3a7804c829b5159ef79
Created May 5, 2015 20:44
Collatz sequence counter
def collatz_count_until_1(n):
count = 0
while n != 1:
if n % 2 == 0:
n = n / 2
else:
n = (3 * n) + 1
count += 1
return count