Skip to content

Instantly share code, notes, and snippets.

View tinshade's full-sized avatar
🔥
Persevere

Abhishek Iyengar tinshade

🔥
Persevere
View GitHub Profile
@tinshade
tinshade / CaptureWebcamImages.py
Created October 29, 2020 11:09
Here's a small script to capture images via webcam using Python3 and OpenCV2. Press 's' to capture and 'q' to cancel. Images are saved in the same directory as the script.
import cv2 #pip install opencv-python
key = cv2. waitKey(1)
webcam = cv2.VideoCapture(0)
while True:
try:
check, frame = webcam.read()
cv2.imshow("Capturing", frame)
key = cv2.waitKey(1)
if key == ord('s'):
cv2.imwrite(filename='saved_img.jpg', img=frame)
@tinshade
tinshade / JavaServer.java
Created November 7, 2020 10:07
A simple Java Server to allow socket connections. Port forwarding the local port can allow of TCP message transmission!
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
public class JavaServer {
public static void main(String[] args) {
connectToServer();
}
@tinshade
tinshade / MailWithGMail.php
Created November 18, 2020 08:10
A simple mailer script with PHP Mailer to send mails via GMail. This does not include attachments but that's pretty easy to do once you get the mail working.
<?php
require('phpmailer/PHPMailerAutoload.php');
//Taking data from a form
$name = trim($_POST['con_name']);
$email = trim($_POST['con_email']);
$subject = trim($_POST['con_subject']);
$message = trim($_POST['con_comment']);
if($name != null && $email != null && $subject != null && $message != null){
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
@tinshade
tinshade / MailWithCPanel.php
Created November 18, 2020 08:11
A simple mailer script with PHP mailer to send mails via CPanel's email service. This does not include attachments.
<?php
require('phpmailer/PHPMailerAutoload.php');
//Getting data from a form
$name = trim($_POST['con_name']);
$email = trim($_POST['con_email']);
$subject = trim($_POST['con_subject']);
$message = trim($_POST['con_comment']);
if($name != null && $email != null && $subject != null && $message != null){
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
@tinshade
tinshade / Fixed_PHPMailerAutoload.php
Created November 18, 2020 08:17
This is a fixed version of PHP autoload. I made this because something in PHP mailer breaks down with PHP v7 and this aims to fix that issue.
<?php
/**
* PHPMailer SPL autoloader.
* PHP Version 5
* @package PHPMailer
* @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
* @author Marcus Bointon (Synchro/coolbru) <[email protected]>
* @author Jim Jagielski (jimjag) <[email protected]>
* @author Andy Prevost (codeworxtech) <[email protected]>
* @author Brent R. Matzelle (original founder)
@tinshade
tinshade / PHP_DB_Config.php
Created November 18, 2020 08:25
Simple PHP database configuration script that automatically switches between local and production databases based on the server it is being run on.
<?php
$whitelist = array('127.0.0.1','::1');
if(!in_array($_SERVER['REMOTE_ADDR'], $whitelist)){
//SERVER
$server = 'localhost';
$username = 'server_username';
$password = 'server_password';
$dbname = 'username_dbname';
$conn = mysqli_connect($server, $username, $password, $dbname);
@tinshade
tinshade / RandomUID.py
Created December 8, 2020 14:31
Generating logcally unique random user ID using pre-installed python modules.
from datetime import datetime
from random import randint
uid = str(datetime.utcnow().strftime('%Y%m%d%H%M%S%f')[:-3]*randint(1,37))
print(f"Here: {uid}\nUse this logically unique ID if you aren't using the traditional +=1 technique!")
@tinshade
tinshade / getlocalmac.js
Created December 23, 2020 08:56
Get the MAC address of a local system. This can be used to ID systems on your network. MAC addresses can be spoofed but are not in most cases and are static unless tampered with so it makes a better ID than a client's IP address.
/*
Get the MAC address of a local system.
This can be used to ID systems on your network.
MAC addresses can be spoofed but are not in most cases
and are static unless tampered with so it makes a better ID than a client's IP address.
*/
const getmac = require('getmac'); //https://www.npmjs.com/package/getmac
const callMac = () =>{
@tinshade
tinshade / Cartoonize.py
Created December 25, 2020 06:08
This program generates a "cartoonized" image of the given input image!
import cv2 #pip install opencv-python
#This program generates a cartoonized image of the given image!
img = cv2.imread("image.jpg")
def color_quantization(img, k):
data = np.float32(img).reshape((-1, 3))
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 20, 1.0)
ret, label, center = cv2.kmeans(data, k, None, criteria, 10, cv2.KMEANS_RANDOM_CENTERS)
center = np.uint8(center)
result = center[label.flatten()]
@tinshade
tinshade / Image_Morph_Effect.py
Last active December 27, 2020 15:59
An Image morphing effect with Python's PIL library.
from PIL import Image
from argparse import ArgumentParser
from random import shuffle
from typing import List, Tuple
def generate_pixels(width: int, height: int) -> List[Tuple[int, int]]:
"""Generates random pixel locations"""
pixels = []
for x in range(width):
for y in range(height):