Skip to content

Instantly share code, notes, and snippets.

View volf52's full-sized avatar
👽
I may be slow to respond.

Muhammad Arslan volf52

👽
I may be slow to respond.
View GitHub Profile
@asdfgeoff
asdfgeoff / NaiveBayesFromScratch.py
Last active November 9, 2020 11:22
A DIY implementation of Multinomial Naive Bayes using NumPy | Details → https://geoffruddock.com/naive-bayes-from-scratch-with-numpy/
from typing import Callable, Union
import numpy as np
import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.utils.validation import check_X_y, check_array
from IPython.display import display
array_like = Union[list, np.ndarray]
matrix_like = Union[np.ndarray, pd.DataFrame]
#Import needed packages
import torch
import torch.nn as nn
from torchvision.datasets import CIFAR10
from torchvision.transforms import transforms
from torch.utils.data import DataLoader
from torch.optim import Adam
from torch.autograd import Variable
import numpy as np
import numpy as np
import multiprocessing as multi
def chunks(n, page_list):
"""Splits the list into n chunks"""
return np.array_split(page_list,n)
cpus = multi.cpu_count()
workers = []
page_list = ['www.website.com/page1.html', 'www.website.com/page2.html'
# library to generate user agent
from user_agent import generate_user_agent
# generate a user agent
headers = {'User-Agent': generate_user_agent(device_type="desktop", os=('mac', 'linux'))}
#headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux i686 on x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.63 Safari/537.36'}
page_response = requests.get(page_link, timeout=5, headers=headers)
@tylerneylon
tylerneylon / mnist.py
Last active April 30, 2022 06:48
A function to load numpy arrays from the MNIST data files.
""" A function that can read MNIST's idx file format into numpy arrays.
The MNIST data files can be downloaded from here:
http://yann.lecun.com/exdb/mnist/
This relies on the fact that the MNIST dataset consistently uses
unsigned char types with their data segments.
"""
@jamesmacwhite
jamesmacwhite / ffmpeg_mkv_mp4_conversion.md
Last active May 13, 2024 10:18
Easy way to convert MKV to MP4 with ffmpeg

Converting mkv to mp4 with ffmpeg

Essentially just copy the existing video and audio stream as is into a new container, no funny business!

The easiest way to "convert" MKV to MP4, is to copy the existing video and audio streams and place them into a new container. This avoids any encoding task and hence no quality will be lost, it is also a fairly quick process and requires very little CPU power. The main factor is disk read/write speed.

With ffmpeg this can be achieved with -c copy. Older examples may use -vcodec copy -acodec copy which does the same thing.

These examples assume ffmpeg is in your PATH. If not just substitute with the full path to your ffmpeg binary.

Single file conversion example

@chdorner
chdorner / README.md
Last active June 23, 2023 20:13
SQLAlchemy scan large table in batches

my database had 72k annotations at the time I ran these benchmarks, here's the result:

$ python scripts/batch_bench.py conf/development-app.ini dumb
Memory summary: start
      types |   # objects |   total size
=========== | =========== | ============
       dict |       13852 |     12.46 MB
  frozenset |         349 |     11.85 MB
VM: 327.29Mb
#!/bin/bash
# update apt-get
export DEBIAN_FRONTEND="noninteractive"
sudo apt-get update
# remove previously installed Docker
sudo apt-get purge lxc-docker*
sudo apt-get purge docker.io*
@robphoenix
robphoenix / spacemacs-cheshe.md
Last active February 6, 2024 23:11
[DEPRECATED] Spacemacs Cheat Sheet - Visit https://github.com/Ben-PH/spacemacs-cheatsheet

This is unmaintained, please visit Ben-PH/spacemacs-cheatsheet

Useful Spacemacs commands

  • SPC q q - quit
  • SPC w / - split window vertically
  • SPC w - - split window horizontally
  • SPC 1 - switch to window 1
  • SPC 2 - switch to window 2
  • SPC w c - delete current window
@mdwhatcott
mdwhatcott / auto-run.py
Created February 20, 2014 05:41
Auto-run `go test` in the console
#!/usr/bin/env python
"""
This script scans the current working directory for changes to .go files and
runs `go test` in each folder where *_test.go files are found. It does this
indefinitely or until a KeyboardInterrupt is raised (<Ctrl+c>). This script
passes the verbosity command line argument (-v) to `go test`.
"""