Skip to content

Instantly share code, notes, and snippets.

View leovujanic's full-sized avatar

Leo Vujanić leovujanic

View GitHub Profile
@leovujanic
leovujanic / fb-fetch-paginated.py
Created March 2, 2024 06:44
Fetch paginated data from Facebook Graph API and save it to the CSV file
import csv
import typing as t
import requests
PER_PAGE = 250
MAX_ITERATIONS = 1000
def fetch_all_data(access_token: str, endpoint: str, search_params: t.Optional[list[str]]) -> list[dict]:
print(f"Fetching data for {endpoint}")
@leovujanic
leovujanic / copy_files_with_rename.sh
Created May 26, 2023 07:58
Bash - find by pattern, rename and copy files from one dir to another
#!/bin/bash
SOURCE_DIR=/file-syncer/source-dir
DEST_DIR=/file-syncer/des-dir
TODAY=$(date +%Y-%m-%d)
echo "Running file syncer script: ${TODAY}"
@leovujanic
leovujanic / abstract-unique-validator.ts
Created May 18, 2021 10:40 — forked from zarv1k/abstract-unique-validator.ts
Unique Validator Example for NestJS
import { ValidationArguments, ValidatorConstraintInterface } from 'class-validator';
import { Connection, EntitySchema, FindConditions, ObjectType } from 'typeorm';
interface UniqueValidationArguments<E> extends ValidationArguments {
constraints: [
ObjectType<E> | EntitySchema<E> | string,
((validationArguments: ValidationArguments) => FindConditions<E>) | keyof E,
];
}
@leovujanic
leovujanic / MermaidGraphView.js
Created February 13, 2020 13:40
Mermaid used in React component
import React from "react";
import * as mermaid from "mermaid";
export default class MermaidGraphView extends React.Component {
constructor (props) {
super(props);
this.graphContainer = React.createRef();
@leovujanic
leovujanic / traefik_loc_bash_profile.sh
Last active January 29, 2020 09:57
Traefik loc bash profile function
tloc() {
if [[ "${1}" == "start" ]]; then
echo "Starting Traefik Loc"
docker run -d -p 9999:9999 -p 80:80 -p 443:443 -v /var/run/docker.sock:/var/run/docker.sock:ro --name traefik_loc --restart unless-stopped --network web vujanile/traefik-loc:latest
if [ $? -ne 0 ]; then
docker restart traefik_loc
fi
return 0
fi
if [[ "${1}" == "restart" ]]; then
@leovujanic
leovujanic / docker-compose.yml
Created December 20, 2019 11:30
Wordpress docker compose - for edu
version: "3.7"
services:
wp:
image: wordpress
restart: unless-stopped
volumes:
- ./wp:/var/www/html
ports:
- 8080:80
@leovujanic
leovujanic / mac_docker_bash_completion_setup.sh
Created December 16, 2019 12:32
Mac - Docker bash completion setup
brew install bash-completion
brew tap homebrew/completions
cd /usr/local/etc/bash_completion.d
ln -s /Applications/Docker.app/Contents/Resources/etc/docker.bash-completion
ln -s /Applications/Docker.app/Contents/Resources/etc/docker-machine.bash-completion
ln -s /Applications/Docker.app/Contents/Resources/etc/docker-compose.bash-completion
@leovujanic
leovujanic / mac_user_key_mapping_switch_y_and_y.sh
Last active December 16, 2019 20:06
Mac user key mapping - switch y and z
hidutil property --set '{"UserKeyMapping": [{"HIDKeyboardModifierMappingSrc":0x70000001c, "HIDKeyboardModifierMappingDst":0x70000001d}, {"HIDKeyboardModifierMappingSrc":0x70000001d, "HIDKeyboardModifierMappingDst":0x70000001c}] }'
@leovujanic
leovujanic / git_pull_all_branches.md
Created October 5, 2019 09:13
Git pull all branches
  1. git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done

  2. git fetch --all

  3. git pull -all

@leovujanic
leovujanic / curl_check_gzip.sh
Created September 11, 2019 13:35
Check if gzipped content is served
curl http://myaddress.loc --silent --write-out "%{size_download}\n" --output /dev/null
curl http://myaddress.loc --silent -H "Accept-Encoding: gzip,deflate" --write-out "%{size_download}\n" --output /dev/null