Monday, October 3
Shadow

Example of Spring Boot REST Controller using SpringDoc OpenAPI

gist
package br.com.zup.edu.app10.samples.authors; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.headers.Header; import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.ExampleObject; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import org.springframewor...

SSH into google colab

gist
#CODE #Generate root password import random, string password = ''.join(random.choice(string.ascii_letters + string.digits) for i in range(20)) #Download ngrok ! wget -q -c -nc https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip ! unzip -qq -n ngrok-stable-linux-amd64.zip #Setup sshd ! apt-get install -qq -o=Dpkg::Use-Pty=0 openssh-server pwgen > /dev/null #Set root password ! echo root:$password | chpasswd ! mkdir -p /var/run/sshd ! echo "PermitRootLogin yes" >> /etc/ssh/sshd_config ! echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config ! echo "LD_LIBRARY_PATH=/usr/lib64-nvidia" >> /root/.bashrc ! echo "export LD_LIBRARY_PATH" >> /root/.bashrc #Run sshd get_ipython().system_raw('/usr/sbin/sshd -D &') #Ask token print("Copy authtoken from https://dashboard.ngrok....

10-terminal-commands-to-speed-up-macos-sierra-on-your-mac.sh

gist
# from : 10 terminal commands to speed up your Mac | defaults-write.com # https://www.defaults-write.com/10-terminal-commands-to-speed-up-macos-sierra-on-your-mac/ #1. Disable animations when opening and closing windows. defaults write NSGlobalDomain NSAutomaticWindowAnimationsEnabled -bool false #2. Disable animations when opening a Quick Look window. defaults write -g QLPanelAnimationDuration -float 0 #3. Accelerated playback when adjusting the window size (Cocoa applications). defaults write NSGlobalDomain NSWindowResizeTime -float 0.001 #4. Disable animation when opening the Info window in Finder (cmd⌘ + i). defaults write com.apple.finder DisableAllAnimations -bool true #5. Disable animations when you open an application from the Dock. defaults write com.apple.dock launchanim ...

Example implementation of gauss elimination in javascript

gist
function print(M, msg) { console.log("======" + msg + "=========") for(var k=0; k<M.length; ++k) { console.log(M[k]); } console.log("==========================") } function diagonalize(M) { var m = M.length; var n = M[0].length; for(var k=0; k<Math.min(m,n); ++k) { // Find the k-th pivot i_max = findPivot(M, k); if (A[i_max, k] == 0) throw "matrix is singular"; swap_rows(M, k, i_max); // Do for all rows below pivot for(var i=k+1; i<m; ++i) { // Do for all remaining elements in current row: var c = A[i][k] / A[k][k]; for(var j=k+1; j<n; ++j) { A[i][j] = A[i][j] - A[k][j] * c; } // Fill lower triangular matrix with zeros A[i][k]...

Abstract class and method program

gist
// --------- CLASS: ANIMAL ------------------ // Abstract class with abstract method abstract class Animal { public void canRun() { System.out.println("Animal can run"); } // Abstract method - has no definition public abstract void canFly(); public abstract void canSwin(); } // --------- CLASS: LION -------------------- // Abstract class with abstract method // So Lion has total 3 methods in it to call class Lion extends Animal { public void canFly() { System.out.println("Lion cannot fly"); } public void canSwin() { System.out.println("Lion can swim"); } } // --------- CLASS: MAIN -------------------- // Abstract class with abstract method // So Lion has total 3 methods in it to call class Main { public static void main(...

Syncword insert/sync tools, somewhat borked

gist
#include <cstdio> #include <stdint.h> #include <fstream> /* syncword will be inserted every SYNCWORD_INTERVAL 64-bit chunks */ #define SYNCWORD_INTERVAL 10 int main(int argc, char *argv[]) { const uint64_t syncword = 0x1acffc1d69420694; if(argc < 3) { fprintf(stderr, "%s - take binary file and add a syncword(0x%llx) to it\n", argv[0], syncword); fprintf(stderr, "usage: %s input output\n", argv[0]); return 1; } std::ifstream input(argv[1], std::ios::binary); if(!input.is_open()) { fprintf(stderr, "could not open %s\n", argv[1]); return 1; } std::ofstream output(argv[2], std::ios::binary); if(!output.is_open()) { fprintf(stderr, "could not open %s\n", argv[1]); ...

OpenCV Player

gist
import logging import cv2 def main(): cap = cv2.VideoCapture("uhU.webm") cap.set(cv2.CAP_PROP_POS_MSEC, 1000.0) #cap.set(cv2.CAP_PROP_POS_FRAMES, 1000.0) w, h = cap.get(cv2.CAP_PROP_FRAME_WIDTH), cap.get(cv2.CAP_PROP_FRAME_HEIGHT) fps = cap.get(cv2.CAP_PROP_FPS) stop = False while not stop: # Read frame ret, frame = cap.read() if ret == False: raise RuntimeError("Failed to read frame") frame_i = cap.get(cv2.CAP_PROP_POS_FRAMES) # Resize #breakpoint() frame = cv2.resize(frame, tuple(int(d*0.33) for d in frame.shape[1:None:-1])) # Display cv2.imshow("Frame", frame) if cv2.waitKey(25) == ord("q"): stop = True break if not cap.isOpe...

Debian 10 (Buster) — Full sources.list

gist
deb http://deb.debian.org/debian buster main contrib non-free deb-src http://deb.debian.org/debian buster main contrib non-free deb http://deb.debian.org/debian buster-updates main contrib non-free deb-src http://deb.debian.org/debian buster-updates main contrib non-free deb http://deb.debian.org/debian buster-backports main contrib non-free deb-src http://deb.debian.org/debian buster-backports main contrib non-free deb http://security.debian.org/debian-security/ buster/updates main contrib non-free deb-src http://security.debian.org/debian-security/ buster/updates main contrib non-free

Solution to level 6 in Untrusted

gist
/**************** * drones101.js * **************** * * Do you remember, my dear Professor, a certain introductory * computational rationality class you taught long ago? Assignment * #2, behavior functions of autonomous agents? I remember that one * fondly - but attack drones are so much easier to reason about * when they're not staring you in the face, I would imagine! */ function startLevel(map) { function moveToward(obj, type) { var target = obj.findNearest(type); var leftDist = obj.getX() - target.x; var upDist = obj.getY() - target.y; var direction; if (upDist == 0 && leftDist == 0) { return; } if (upDist > 0 && upDist >= leftDist) { direction = 'up'; } else if (upDist < ...

A TicTacToe game

gist
import random board = ["-","-","-","-","-","-","-","-","-"] pl_in = {"a1":1,"a2":2,"a3":3,"b1":4,"b2":5,"b3":6,"c1":7,"c2":8,"c3":9} winner = None game_run = True def printBoard(board): print(board[0]+" | "+board[1]+" | "+board[2]) print("----------") print(board[3]+" | "+board[4]+" | "+board[5]) print("----------") print(board[6]+" | "+board[7]+" | "+board[8]) print("----------") def playerFirstSelect(): player = random.choice(["X","O"]) return player def playerInput(): inp_int = input("a1 a2 a3 \t b1 b2 b3 \t c1 c2 c3 : ") inp = pl_in[inp_int] if(board[inp-1] == "-"): board[inp-1] = player else: print("Sorry, it's already taken.You can choose any other ") i...