Skip to content

Instantly share code, notes, and snippets.

View mirfan899's full-sized avatar
🏠
Working from home

Muhammad Irfan mirfan899

🏠
Working from home
View GitHub Profile
@mirfan899
mirfan899 / detect_crop.py
Created November 9, 2022 10:17 — forked from mcclux/detect_crop.py
Python script using dlib to detect and save faces from a set of source images
import os
import sys
import dlib
import matplotlib.pyplot as plt
from PIL import Image
# adjust these variables as necessary
# dirname is the directory relative to the script where the files to detect a face and crop live
dirname = "source"
@mirfan899
mirfan899 / xml_split.py
Created October 27, 2022 07:09 — forked from benallard/xml_split.py
Small python script to split huge XML files into parts. It takes one or two parameters. The first is always the huge XML file, and the second the size of the wished chunks in Kb (default to 1Mb) (0 spilt wherever possible) The generated files are called like the original one with an index between the filename and the extension like that: bigxml.…
#!/usr/bin/env python
import os
import xml.parsers.expat
from xml.sax.saxutils import escape
from optparse import OptionParser
from math import log10
# How much data we process at a time
@mirfan899
mirfan899 / xml_split.py
Created October 27, 2022 07:09 — forked from scnctech/xml_split.py
I took this gist https://gist.github.com/benallard/8042835 and modified it a little so it worked for my needs. (mainly encoding issues and bigger file chunks)
#!/usr/bin/env python
#based off this gist https://gist.github.com/benallard/8042835
#modified it a little so it worked for my needs. (mainly encoding issues and bigger file chunks)
import os
import xml.parsers.expat
from xml.sax.saxutils import escape
from optparse import OptionParser
from math import log10
@mirfan899
mirfan899 / ubuntu-20.04-macbook-pro.md
Created May 31, 2022 05:37 — forked from johnjeffers/ubuntu-20.04-macbook-pro.md
Ubuntu 20.04 on a 15" Retina MacBook Pro (Mid-2014)

Ubuntu 20.04 on a 15" Retina MacBook Pro (Mid-2014)

These are notes from my efforts to get Ubuntu 20.04 installed on my older MacBook Pro. I'm making this gist public in the hopes that it's helpful to others.

I did a Minimal install, but selected the option to install additional 3rd-party drivers.

Wifi doesn't work during the install (because it requires a 3rd-party driver), so you won't be able to choose to download updates while installing. No big deal, run a software update after the install.

The installer takes about 25 minutes to complete. Post-install, most things work. The only driver I had to manually install was for the FaceTime camera. More on that below.

@mirfan899
mirfan899 / wn3.1.py
Created November 2, 2021 15:23 — forked from e-mon/wn3.1.py
WordNet in NLTK version up from 3.0 to 3.1
import os
nltkdata_wn = '/path/to/nltk_data/corpora/wordnet/'
wn31 = "http://wordnetcode.princeton.edu/wn3.1.dict.tar.gz"
if not os.path.exists(nltkdata_wn+'wn3.0'):
os.mkdir(nltkdata_wn+'wn3.0')
os.system('mv '+nltkdata_wn+"* "+nltkdata_wn+"wn3.0/")
if not os.path.exists('wn3.1.dict.tar.gz'):
os.system('wget '+wn31)
os.system("tar zxf wn3.1.dict.tar.gz -C "+nltkdata_wn)
@mirfan899
mirfan899 / ms-concepts-import.sh
Created September 15, 2021 07:23 — forked from jexp/ms-concepts-import.sh
Load and query the Microsoft Concept Graph in Neo4j https://concept.research.microsoft.com/Home/Introduction
function import_extract_first {
echo "name:ID(Concept)" > concepts.txt
cat data-concept-instance-relations.txt | cut -d $'\t' -f 1 | sort | uniq >> concepts.txt
echo "name:ID(Instance)" > instances.txt
cat data-concept-instance-relations.txt | cut -d $'\t' -f 2 | sort | uniq >> instances.txt
echo $':END_ID(Concept)\t:START_ID(Instance) relations:int' > is_a.hdr
$NEO4J_HOME/bin/neo4j-import --into concepts.db --id-type string --delimiter TAB --bad-tolerance 13000000 --skip-duplicate-nodes true --skip-bad-relationships true \
@mirfan899
mirfan899 / iamshell.txt
Last active April 24, 2021 06:23
shell
https://drive.google.com/drive/folders/14rA9c0cpK2XptZVDNi7-24jooPEJWKgm?usp=sharing
@mirfan899
mirfan899 / perplexity.py
Created March 30, 2021 05:03 — forked from huikang/perplexity.py
calculate perplexity
import math
import torch
from transformers import BertTokenizer, BertModel, BertForMaskedLM, OpenAIGPTLMHeadModel, OpenAIGPTTokenizer
# Load pre-trained model (weights)
model = OpenAIGPTLMHeadModel.from_pretrained('openai-gpt')
model.eval()
# Load pre-trained model tokenizer (vocabulary)
tokenizer = OpenAIGPTTokenizer.from_pretrained('openai-gpt')
@mirfan899
mirfan899 / draw_text_with_background_opencv.py
Created February 1, 2021 13:19 — forked from aplz/draw_text_with_background_opencv.py
draw text with background // opencv
import cv2 # opencv
import numpy as np
font_scale = 1.5
font = cv2.FONT_HERSHEY_PLAIN
# set the rectangle background to white
rectangle_bgr = (255, 255, 255)
# make a black image
img = np.zeros((500, 500))
@mirfan899
mirfan899 / app.py
Created January 9, 2021 10:51 — forked from greyli/app.py
Photo upload and manage with Flask and Flask-Uploads (Multiple file upload support!).
# -*- coding: utf-8 -*-
import os
import uuid
from flask import Flask, render_template, redirect, url_for, request
from flask_uploads import UploadSet, configure_uploads, IMAGES, patch_request_class
from flask_wtf import FlaskForm
from flask_wtf.file import FileField, FileRequired, FileAllowed
from wtforms import SubmitField