Skip to content

Instantly share code, notes, and snippets.

@porthunt
porthunt / read_github_json.py
Created Aug 6, 2021
Read json file from a private GitHub repository
View read_github_json.py
import base64
import json
import requests
REPO_URL = "https://api.github.com/repos/<USER>/<REPO>/contents/<PATH>/<TO>/<FILE>.json"
TOKEN = "<YOUR PAT OR OAUTH TOKEN>"
headers = {
"Authorization": f"token {TOKEN}",
"Accept": "application/vnd.github.v4+raw"
View tmux_cheatsheet.markdown

tmux cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
View linked-list.py
# please define a very simple singly linked list
# list items: 4 -> 7 -> 2
# item positions: 0 1 2
# please write a function that, given a value and a position, inserts the value into the list at that position
# 4,7,2 => insert 9 at position 1 => 4,9,7,2
class LinkedList(object):
def __init__(self):
HEAD = None
@porthunt
porthunt / MapScript.cs
Last active Apr 28, 2017
A different approach to work on the Text101 challenge from Udemy Unity Course
View MapScript.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class World
{
LinkedList<Map> map_list;
Map curr_map;
public World()
View rating.py
import pandas
import operator
import math
import sys
dataframe = None
file_name = None
rating_limits = (0.5, 5.0)
View pyrsing.py
import speech_recognition as sr
'''
Installation:
pip install SpeechRecognition
On OSX: brew install portaudio && brew link portaudio
pip install pyaudio
Check for more info: https://pypi.python.org/pypi/SpeechRecognition/
@porthunt
porthunt / str_conversion.r
Last active Mar 7, 2016
String conversion
View str_conversion.r
setwd("C:/Users/user/Desktop") #Use the path that your file is in.
names <- readLines("ALL.txt") #Read file
listOfNames <- ""
for (i in names) { listOfNames <- paste(listOfNames,",",i) }
listOfNames <- gsub(" ", "", listOfNames) #Remove whitespaces
substr(listOfNames, 2, nchar(listOfNames)) #Remove first comma
# Given a file with strings in the following format:
#
# A
View DigestCalculator.java
/* Developed by: Joao Pedro Portela Gomez Vaz */
/* COMPLETE - Ver. 1.5 */
import java.io.*;
import java.security.*;
import java.util.*;
/* HOW TO RUN */
// 1. cd /your/directory
// 2. javac DigestCalculator.java
View CreateSignature.java
import java.security.*;
import javax.crypto.*;
class CreateSignature {
public static void main (String[] args) throws Exception {
// verify args. If args.length is not more (or less) than 1, tells how to use the program.
if (args.length !=1) {
System.err.println("How to use: java CreateSignature your text between \"\"");
View TicTacToeTomek.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define rows 4
#define cols 4
void checkIfWinner(char boardMap[rows][cols], int k);
int checkDiagonal(char board[rows][cols], char side);
int checkGameStatus(char board[rows][cols]);