Skip to content

Instantly share code, notes, and snippets.

@karthikax
karthikax / delete_if_name.php
Last active August 29, 2015 14:23
PHP if file name contains 'word' delete it.
$dir = '.';
$files = scandir($dir);
foreach ( $files as $file ) {
if ( strpos($file,'word') !== false ) {
unlink( $file );
}
}
@karthikax
karthikax / hosts
Last active December 29, 2022 20:04
Adding virtual hosts in wamp (For any Directories)
//Add to hosts file in "C:\Windows\System32\drivers\etc\"
127.0.0.1 newsite
//Access your new directory via "http://newsite"
@karthikax
karthikax / dosu.php
Last active December 31, 2022 06:16
PHP Download file to server from URL
<html>
<p style="width: 70%;margin: auto;margin-top: 5%;font-size:larger;text-align:center">
Download a file from any URL</p>
<form method="post" style="width: 70%;margin: auto;margin-top: 10%;">
<input name="url" size="50" placeholder="Source URL" style="width: 100%;height: 10%;font-size: 1.5em;padding:10px" required>
<input name="submit" type="submit" value="Download" style="width: 30%;height: 10%;margin: 5% auto; display: block;">
<p style="width: 70%;margin: auto;margin-top: 10%;font-size:larger;text-align:center">
To <?php echo getcwd(); ?></p>
<p style="width: 70%;margin: auto;font-size: smaller;text-align: center;position: fixed;bottom: 0;background: #fff;">
Powered by: <a href="https://karthikbhat.net/portfolio" target="_blank" style="color:#f60;text-decoration:none;">Karthik</a></p>
@karthikax
karthikax / edit_last_commit.sh
Last active October 27, 2017 12:17
Git commit in the past
cd path/to/git/project
export GIT_COMMITTER_DATE="YYYY-MM-DD HH:MM:SS"
export GIT_AUTHOR_DATE="YYYY-MM-DD HH:MM:SS"
git commit --amend --date=""YYYY-MM-DD HH:MM:SS"
# Verify date and time then save.
unset GIT_COMMITTER_DATE
unset GIT_AUTHOR_DATE
@karthikax
karthikax / ussd.txt
Created November 2, 2017 07:28
Airtel 4G Special (Monthly Unlimited) Packs USSDs
*125*
*125*1541#
*125*1537#
@karthikax
karthikax / cloudflare_check.php
Created February 12, 2018 19:18
Check Access via Cloudflare in PHP
<?php
if ( ! isset($_SERVER['HTTP_CF_VISITOR']) && ! isset($_SERVER['HTTP_CF_CONNECTING_IP']) ) {
die('Direct Access');
}
echo 'Cloudflare Access';
@karthikax
karthikax / install.sh
Last active February 13, 2018 20:08
One click LAMP Set up
#!/bin/bash
# @todo: NOT WORKING PROPERLY
MYSQL_PASSWORD="KarthikMSQL&398"
DATABASE_NAME="wpkart"
SERVER_NAME="karthikbhat.net"
sudo apt-get -y install apache2
@karthikax
karthikax / Dockerfile
Created December 27, 2019 17:33
Docker basics
FROM python:3
# From here: https://hub.docker.com/_/python
# Python preinstalled
# You can use any image from docker hub
WORKDIR /usr/src/app
COPY my_file.py ./
# Copy any file or directory here if needed.
@karthikax
karthikax / greenlet-meta.js
Created October 26, 2020 20:04
Greenlet meta fix
(function () {
'use strict';
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
@karthikax
karthikax / minify.js
Created January 11, 2021 10:16
JSON file minify
const fs = require('fs');
const data = fs.readFileSync( process.argv[2], { encoding: 'utf8', flag: 'r' } );
const min = JSON.parse(data, (key, value) =>
typeof value === "number" ? Math.round(value * 100) / 100 : value
)
const minString = JSON.stringify( min )