Skip to content

Instantly share code, notes, and snippets.

View sakydev's full-sized avatar

Saqib Razzaq sakydev

View GitHub Profile
@sakydev
sakydev / proxy_rotation_for_scrapy.py
Last active March 1, 2023 12:34
py+scrapy: simple proxy rotation with python
import random, logging
from datetime import datetime, timedelta, date
class ProxiesRotation(object):
"""docstring for ProxiesRotation"""
def __init__(self, directory):
super(ProxiesRotation, self).__init__()
self.proxies = []
self.forbidden_proxies = []
self.directory = directory
self.usedProxies = {}
@sakydev
sakydev / select_database_items_dynamic_with_php.php
Last active September 3, 2021 09:30
php+mysql: dynamic PHP function to select anything from a mysql table
<?php
// Please replace TABLE:: actions with your own DB class
// I wrote this class while working with a Laravel based project
// Function is also being used in a project of mine called BriskLimbs
public function list($parameters = array()) {
$fields = array('*');
$limit = $this->limit;
if (!empty($parameters['limit'])) {
@sakydev
sakydev / mailgun_phpsdk.php
Last active September 3, 2021 09:30
php+mailgun: send email with mailgun php sdk
<?php
// requires Mailgun PHP SDK https://github.com/mailgun/mailgun-php
require 'vendor/autoload.php';
use Mailgun\Mailgun;
function sendMail($params) {
    $from = isset($params['from']) ? $params['from'] : '[email protected]';
    $mailParams = array();
    $attachments = array();
@sakydev
sakydev / command_on_multiple_mysql_tables.php
Last active September 3, 2021 09:29
php+mysql: script to run same command on multiple tables
<?php
$query = "alter table {table} drop column columnName;";
$tables = array('tableA', 'tableB');
foreach ($tables as $key => $source) {
    $currentQuery = str_replace('{table}', $source, $query);
    DB::query($currentQuery);
}
@sakydev
sakydev / rotate_videos_in_directory.php
Last active September 3, 2021 09:32
php+ffmpeg: rotate all videos in a directory by specified degrees
<?php
// Requires FFMPEG to be installed and globally available
// Been using this to rotate videos shot on a phone with dead sensors
if (!$argv['1']) { exit("php rotate_360.php input_dir output_dir degress_to_rot"); }
$input_dir = $argv['1'];
$output_dir = $argv['2'];
if (!file_exists($output_dir)) { @mkdir($output_dir); }
@sakydev
sakydev / convert_all_videos_directory.php
Last active September 3, 2021 09:32
php+ffmpeg: convert high size smartphone videos with minimal quality loss
<?php
// My smartphone Note 8 outputs really heavy size videos. So I wrote this script
// to automatically convert videos in given directory
$inputDir = 'directory_with_all_videos';
$outputDir = 'directory_to_save_converted_videos_to';
$files = glob($inputDir);
@sakydev
sakydev / organize_files.py
Last active September 3, 2021 09:28
py: organize a directory by file type
# iterates over each file in source directory
# and moves to target directory under folders by file type
# I'm using this to automatically cleanup my Downloads folder on Windows 10
# which always looked like a mess before
from os import listdir, path, mkdir, rename
import shutil
inputDir = 'C:/Users/{user}/Downloads'
outputDir = 'G:/Downloads'