Skip to content

Instantly share code, notes, and snippets.

@ioanzicu
ioanzicu / minimumMoves.js
Created January 14, 2021 06:11
Minimum Moves task from Hacker Rank!
function minimumMoves(arr1, arr2) {
if (arr1.length != arr2.length) {
return 0;
}
let moves = 0;
arr1.map((elem, index) => {
let tempElemArr1 = elem.toString().split('')
let tempElemArr2 = arr2[index].toString().split('');
tempElemArr1.map((num, index2) =>{
@ioanzicu
ioanzicu / pdf_watermark.py
Created December 28, 2020 01:20
Add a watermark to each page of a PDF file.
from PyPDF2 import PdfFileReader, PdfFileWriter
output = PdfFileWriter()
input_pdf = PdfFileReader(open('./pdf/super.pdf', 'rb'))
watermark_pdf = PdfFileReader(open('./pdf/wtr.pdf', 'rb'))
watermark = watermark_pdf.getPage(0)
for i in range(input_pdf.getNumPages()):
@ioanzicu
ioanzicu / JPGtoPNGConverter.py
Created December 26, 2020 22:36
Convert JPG / JPEG images into PNG format.
import sys
import os
from PIL import Image
# Run the script with: python JPGtoPNGConverter.py source_folder/ destination_folder/
# Grab 2 arguments
try:
source_folder = sys.argv[1]
destination_folder = sys.argv[2]
from random import randint
import sys
try:
min_num = int(sys.argv[1])
max_num = int(sys.argv[2])
if min_num >= max_num:
print(f'Input Minimum: {min_num} Maximum: {max_num} NOT VALID.')
print('Minimum value should be less than maximum value!')
@ioanzicu
ioanzicu / squash-git-commits.sh
Created August 13, 2020 06:31
Squash many commits into one new with a new message.
# HEAD~4 where 4 is the number of commits that will be squashed
git reset --soft HEAD~4 && git commit -m "One message for new commit"
@ioanzicu
ioanzicu / time.go
Created July 30, 2020 07:21
Conversion of the unix timestamp in type int64 to string and from string to int64 in GO.
package main
import (
"fmt"
"time"
"strconv"
)
func main() {
fmt.Printf("%+v %T\n",time.Now(),time.Now())
let a1 = [123, 543];
let a2 = [321, 279];
function solution(arr1, arr2) {
let sum = 0;
let digits = 0;
arr1.map((num, i) => {
// convert each number to array of string - for each digit
// ["1", "2", "3"]
digitsArr1 = (""+num).split("");
@ioanzicu
ioanzicu / transformString.js
Created April 14, 2020 13:10
Transform a string by removing a letter A with an adjacent letter B or by removing a letter C together with an adjacent letter D.
function solution(s){
let i = 0;
while(i <= s.length) {
if (s.includes("AB"))
s = s.replace("AB", "");
else if (s.includes("BA"))
s = s.replace("BA", "");
else if (s.includes("CD"))
s = s.replace("CD", "");
else if (s.includes("DC", ""))
@ioanzicu
ioanzicu / Graphs.c
Created April 13, 2020 07:54
Breadth First Search and Depth First Search
#include<stdio.h>
#include<stdlib.h>
// QUEUE
struct Node {
int data;
struct Node *next;
} *front = NULL, *rear = NULL;
void enqueue(int value) {
#include<stdio.h>
void ShellSort(int A[], int n) {
int gap, i , j, temp;
for (gap = n/2; gap >= 1; gap /= 2) {
for (i = gap; i < n; ++i) {
temp = A[i];
j = i - gap;
while (j >= 0 && A[j] > temp) {