Skip to content

Instantly share code, notes, and snippets.

View Phoenix-Effect's full-sized avatar

Suhail Ghafoor Phoenix-Effect

View GitHub Profile
@Phoenix-Effect
Phoenix-Effect / pdf_hasher.py
Last active February 10, 2024 20:35
This code is an example of how a PDF hash can be calculated while ignoring the '/ID' identifier in the trailer of the file. This '/ID' part is modified each time the file is saved even if the contents have not been modified. This leads to files with identical contents generating different hashes. The python script opens a given PDF file in binar…
# run using python pdf_hasher.py <pdf_file_path.pdf>
# add -v argument to print the portions of the file which
# are excluded in hash calculation.
import hashlib
import argparse
import sys
def hash_file_exclude_id(file_path, verbose=False):
"""Hashes a file excluding the /ID entry in the PDF trailer and optionally prints excluded parts."""
@Phoenix-Effect
Phoenix-Effect / random.sh
Last active November 14, 2019 06:08
This script generators a random number in bash and saves it to a variable.
#!/bin/bash
NUM=$(shuf -i 100-300 -n 1)
echo $NUM
@Phoenix-Effect
Phoenix-Effect / articles.py
Created July 27, 2018 01:28
Downloads a bunch of DOI numbers from airtable, gets information related to that DOI number and upload it back to airtable.
from habanero import Crossref
from airtable import Airtable
from airtable.auth import AirtableAuth
import time
import pprint
import requests
import datetime
import html.parser
apikey = "API KEY"
@Phoenix-Effect
Phoenix-Effect / googlebooks_to_airtable.py
Created July 17, 2018 23:20
Pulls ISBN numbers/titles from an airtable and then download's the book information from google books and reuploads to airtable.
import os
import re
from airtable import Airtable
from airtable.auth import AirtableAuth
import requests
import pprint
from pathlib import Path
APIKEY = "ENTER THIS"
BASEURL = "ENTER THIS"
@Phoenix-Effect
Phoenix-Effect / bam_index.sh
Created July 15, 2018 10:08
Checks if the bam index files in a directory are newer than their corresponding bam files.
#!/bin/bash
# Directory of the directory you want to scan
DIR="ENTER DIRECTORY HERE"
TOTALBAMS=0
OLDINDEX=0
UNINDEXED=0
for file in $DIR*.bam; do # Iterate over all bam files in given directory
@Phoenix-Effect
Phoenix-Effect / main.py
Last active February 11, 2022 22:00
Scrape videos data from youtube and push to airtable. By default reads from videos.txt but can defined with an argument.
import pafy
import os
import glob
import re
from airtable import Airtable
from airtable.auth import AirtableAuth
import requests
from pathlib import Path
from webvtt import WebVTT
@Phoenix-Effect
Phoenix-Effect / frequency.java
Created July 3, 2018 08:07
Count frequency of a string in a given array without using any functions or classes in Java.
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Main {
static void staircase(String[] votes) {
@Phoenix-Effect
Phoenix-Effect / main.java
Created July 3, 2018 01:03
Example of how you can read and parse JSON file in Java. Requires JSON library.
import org.json.*;
import java.io.*;
public class main {
public static JSONObject obj;
public static void main(String args[]){
try {
obj = new JSONObject( fileToString("src/main/resources/questions.json") );
JSONArray questionsArray = obj.getJSONArray("question");
@Phoenix-Effect
Phoenix-Effect / videoThumbnail.php
Created July 3, 2018 00:52
Given a url of a video hosted on ted, youtube or vimeo, finds where the video is hosted and outputs the thumbnail for that video.
<?php
function outputVideoThumbnail($url){
$parsed_url = parse_url($url);
// if youtube is detected
if($parsed_url['host']=='www.youtube.com') {
$query = $parsed_url['query'];
$Arr = explode('v=',$query);
$videoIDwithString = $Arr[1];