Skip to content

Instantly share code, notes, and snippets.

import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
fname = 'daniel-plan-u1WcrpHk6Pg-unsplash.jpg'
image = Image.open(fname).convert("L")
img_mat = np.asarray(image)
plt.imshow(img_mat, cmap='gray', vmin=0, vmax=255)
plt.show()
@simrit1
simrit1 / PyDa.py
Created July 28, 2021 04:17 — forked from adameubanks/PyDa.py
Code for the video where we build a Jarvis like virtual assistant in python 3
import wolframalpha
client = wolframalpha.Client("lilpumpsaysnopeeking")
import wikipedia
import PySimpleGUI as sg
sg.theme('DarkPurple')
layout =[[sg.Text('Enter a command'), sg.InputText()],[sg.Button('Ok'), sg.Button('Cancel')]]
window = sg.Window('PyDa', layout)
#!/usr/bin/env python3
"""A recursive-descent arithmetic calculator."""
import re
from collections import namedtuple
from fractions import Fraction
Parse = namedtuple('Parse', 'value, index')
FAILURE = Parse(None, -1)
@simrit1
simrit1 / guad.py
Created July 28, 2021 04:44 — forked from c0d3x27/guad.py
Make Your Pc Notify Your Phone Whenever There is Movement Around it
import cv2
guardcam = cv2.VideoCapture(0)
while guardcam.isOpened():
ret, frame1 = guardcam.read()
ret, frame2 = guardcam.read()
diff = cv2.absdiff(frame1, frame2)
gray = cv2.cvtColor(diff, cv2.COLOR_RGB2GRAY)
blur = cv2.GaussianBlur(gray, (5, 5), 0)
_, thresh = cv2.threshold(blur, 20, 255, cv2.THRESH_BINARY)
dilated = cv2.dilate(thresh, None, iterations=3)
@simrit1
simrit1 / shared_memory_tests.py
Created July 28, 2021 05:07 — forked from s-m-e/shared_memory_tests.py
Pure Python & Numpy openMP-style for-loop based on POSIX shared memory and forks for Unix-like systems
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
SHARED MEMORY TESTS
Pure Python & Numpy openMP-style for-loop based on POSIX shared memory
and forks for Unix-like systems (tested on Linux)
Copyright (C) 2021 Sebastian M. Ernst <[email protected]>
@simrit1
simrit1 / png_out.py
Created July 28, 2021 05:11 — forked from darka/png_out.py
Generating a PNG in Python
import struct
import zlib
from typing import BinaryIO, List, Tuple
Pixel = Tuple[int, int, int]
Image = List[List[Pixel]]
BLACK_PIXEL: Pixel = (0, 0, 0)
WHITE_PIXEL: Pixel = (255, 255, 255)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import logging
from argparse import ArgumentParser
logger = logging.getLogger(__name__)
def data():
logger.info('run data func')
from transformers import pipeline
from txtai.pipeline import HFTrainer
# Training data
data = [
{"question": "What ingredient?", "context": "Pour 1 can whole tomatoes", "answers": "tomatoes"},
{"question": "What ingredient?", "context": "Dice 1 yellow onion", "answers": "onion"},
{"question": "What ingredient?", "context": "Cut 1 red pepper", "answers": "pepper"},
{"question": "What ingredient?", "context": "Peel and dice 1 clove garlic", "answers": "garlic"},
{"question": "What ingredient?", "context": "Put 1/2 lb beef", "answers": "beef"},
import math
import numpy as np
from timebudget import timebudget
from multiprocessing import Pool
iterations_count = round(1e7)
def complex_operation(input_index):
print("Complex operation. Input index: {:2d}".format(input_index))