Skip to content

Instantly share code, notes, and snippets.

def put_surplus_var(tab):
rows = len(tab)
cols = len(tab[0])
cols_add = rows - 1
tab = [x + [0]*cols_add for x in tab]
for i in range(1, rows):
for j in range(1, rows):
if i ==j:
.text
main:
# Print string msg1
li $v0,4 # print_string syscall code = 4
la $a0, msg1 # load the address of msg
syscall
# Get input n from user and save
li $v0,5 # read_int syscall code = 5
syscall
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
/* Insertion Sort */
void insertion_sort(long long arr[], int n) {
int i, j;
for (i = 1; i < n; i++) {
#include <assert.h>
// Angle from 0000 hrs
int hour_hand_angle(int hour, int min)
{
return hour * 30 + min / 2;
}
// Angle from 0000 hrs
int min_hand_angle(int hour, int min)
@meehatpa
meehatpa / lru.cpp
Created August 17, 2020 05:48
LRU cache cpp implementation
#include <iostream>
#include <list>
#include <map>
class cache {
public:
cache(int s) : size(s) {};
void put(int k) {
@meehatpa
meehatpa / http_get_cmd.py
Last active August 24, 2020 07:06
Raspberry pi http server to run shell command using http get from client
#!/usr/bin/python3
# Example:
# http://192.168.1.100:8080/?cmd=ls%20-l&cmd=date
#
from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.parse import parse_qs
import subprocess
class Handler(BaseHTTPRequestHandler):
def do_HEAD(self):
@meehatpa
meehatpa / CMakeLists.txt
Created September 22, 2020 11:26
Sample CMakeLists.txt to use add_custom_command
cmake_minimum_required(VERSION 3.16)
project(testcmake)
# Build only when gen.g gets modified
add_custom_command(
OUTPUT ${PROJECT_SOURCE_DIR}/gen
COMMAND ${CMAKE_COMMAND} -E touch ${PROJECT_SOURCE_DIR}/gen
DEPENDS "${PROJECT_SOURCE_DIR}/gen.g"
)
@meehatpa
meehatpa / combine.py
Created February 1, 2021 10:54
Combine chrome trace json
import json
import glob
import os
import re
def clean_json(string):
string = re.sub(",[ \t\r\n]+}", "}", string)
string = re.sub(",[ \t\r\n]+\]", "]", string)
string = re.sub(",$", "", string)
#!/bin/bash
set -e
prefix=/mnt/usb/
# delete dir with size < 5 MB
#DIRRM=`find /mnt/usb -mindepth 1 -maxdepth 1 -type d -exec du -ks {} + | awk '$1 <= 50000' | cut -f 2-`
#IFS='
#'
#for i in $DIRRM; do
# rm -rf $i
@meehatpa
meehatpa / settings.json
Last active June 5, 2021 15:23
Change /etc/systemd/system/multi-user.target.wants/transmission-daemon.service to pick settings.json via ExecStart=/usr/bin/transmission-daemon -f --log-error -g <settings_dir>
{
"alt-speed-down": 50,
"alt-speed-enabled": false,
"alt-speed-time-begin": 540,
"alt-speed-time-day": 127,
"alt-speed-time-enabled": false,
"alt-speed-time-end": 1020,
"alt-speed-up": 50,
"bind-address-ipv4": "0.0.0.0",
"bind-address-ipv6": "::",