Skip to content

Instantly share code, notes, and snippets.

View dmelcer9's full-sized avatar

Daniel Melcer dmelcer9

View GitHub Profile
@dmelcer9
dmelcer9 / nice_index.py
Created December 19, 2024 20:03
A nice multi-level indexing function on tensors
def nice_index(tens: Tensor, index: Tensor) -> Tensor:
"""
A multi-level indexing function.
The last dimension of the index is a multi-level specifier
All other dimensions of the index are batch
For example, if the index is [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
the result will be [[tens[1, 2], tens[3, 4]], [tens[5, 6], tens[7, 8]]]
See tests for more details
"""
@dmelcer9
dmelcer9 / JavadocRedirect.js
Created July 26, 2016 19:20
Super simple chrome extension to banish old javadoc from the web.
chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
console.log("Tab changed");
if(changeInfo.status == 'complete'){
console.log("Tab changed 2");
chrome.tabs.getSelected(null,function(tab){
if(tab){
console.log("Tab defined");
var current = tab.url;
console.log(current);
var regex = /(https?:\/\/docs\.oracle\.com\/javase\/)(.*)(\/docs\/api.*)/i;
@dmelcer9
dmelcer9 / Mandelbrot.cu
Created July 19, 2016 19:24
Generates ASCII art Mandelbrot set using CUDA. Make sure to set your terminal font size as small as possible and adjust the parameters to fit your setup.
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
#include <stdlib.h>
//MAKE SURE TO SET TERMINAL FONT SIZE AS SMALL AS POSSIBLE
#define WIDTH 940 //In chars, adjust to screen
@dmelcer9
dmelcer9 / LegoRefresher.gs
Last active June 22, 2016 18:02
Parses the comments from a Lego Ideas page and gets the frequency of each number.
var LegoURL = "https://ideas.lego.com/comments/project/32812051-934d-4d73-9961-b7a6cc652007/comments?order=newest&from=max"
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Refresh Lego Comments')
.addItem('Refresh', 'RefreshLegoCount')
.addToUi();
}
function RefreshLegoCount() {
@dmelcer9
dmelcer9 / ExampleUsage.java
Created September 3, 2015 23:18
Faster and More Readable than RecursiveQuicksort
import java.util.*;
public class ExampleUsage {
static final int LIST_SIZE = 1000000; //size of list
//Requires about 250-300MB of RAM per million list entries
//Has only been tested with random lists, may require more with sorted lists
public static void main(String[] args) {
@dmelcer9
dmelcer9 / RecursiveQuicksort.java
Last active August 26, 2015 01:21
A RecursiveTask Quicksort
import java.util.*;
import java.util.concurrent.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class RecursiveQuicksort {
static int listLength = 1000000;
public static void main(String[] args) {
@dmelcer9
dmelcer9 / Substring
Created May 7, 2015 14:08
Simple substring implementation
//Simple substr implementation
//Paramaters
//String:the string you want to operate on
//Start:starting position, indexed from 0
//End:ending position, indexed from 0
//Curpos:used internally by the recursion loop- leave blank
//Examples
//echo(substr("Hello world",0,4)); Returns "Hello"