Skip to content

Instantly share code, notes, and snippets.

View sarathlal-old's full-sized avatar
🎯
Focusing

Sarathlal N sarathlal-old

🎯
Focusing
View GitHub Profile
@sarathlal-old
sarathlal-old / transfer-simple.php
Last active August 29, 2015 14:26
Transfer files from server to server with out FTP details.
<?php
// Insert this file on server and go to the path from browser.
set_time_limit(0); //Unlimited max execution time
$path = 'newfile.zip'; // Name of the file to be saved on server
$url = 'http://your_old_domain.com/file.zip'; //File URL to be moved
$newfname = $path;
echo 'Starting Download!<br>';
$file = fopen ($url, "rb");
if($file) {
$newf = fopen ($newfname, "wb");
@sarathlal-old
sarathlal-old / transfer-ftp-put.php
Last active August 29, 2015 14:26
Transfer files from server to server using PHP ftp_put() function
<?php
//Place this file in source server and go to the path
set_time_limit(0); //Unlimited max execution time
$remote_file = '/var/www/file.zip'; //File to be saved in remote server with path
/* FTP Account */
$ftp_host = 'ftp-host.com'; /* host */
$ftp_user_name = 'ftp-username@your-ftp-host.com'; /* username */
$ftp_user_pass = 'ftppassword'; /* password */
@sarathlal-old
sarathlal-old / transfer-copy.php
Created July 29, 2015 10:01
Transfer files from server to server using PHP `copy()` function.
<?php
// Insert this file on server and go to the path from browser.
set_time_limit(0); //Unlimited max execution time
/* Source File URL */
$remote_file_url = 'http://origin-server-url/files.zip';
/* New file name and path for this file */
$local_file = 'files.zip';
@sarathlal-old
sarathlal-old / cleanup.php
Created July 30, 2015 03:26
A simple script to change folder & file permissions of Web Applications like WordPress, Magento etc.
<?php
//Put this file on the installation folder and run script via browser. This script will change all folders permission as 755 & all file's permission as 644.
//Function to set file permissions to 0644 and folder permissions to 0755
function AllDirChmod( $dir = "./", $dirModes = 0755, $fileModes = 0644 ){
$d = new RecursiveDirectoryIterator( $dir );
foreach( new RecursiveIteratorIterator( $d, 1 ) as $path ){
if( $path->isDir() ) chmod( $path, $dirModes );
else if( is_file( $path ) ) chmod( $path, $fileModes );
}
@sarathlal-old
sarathlal-old / Gruntfile.js
Last active August 29, 2015 14:26
Configure few task on Gruntfile.js
// configure jshint to validate all js files -----------------------------------
jshint: {
options: {
reporter: require('jshint-stylish') // use jshint-stylish to make our errors look and read good
},
// when this task is run, lint the Gruntfile and all js files in src
build: ['src/js/*.js']
}
@sarathlal-old
sarathlal-old / sample.htaccess
Created August 3, 2015 10:58
Page optimization snippets for .htaccess ( Apache serevr )
## Diflate compression :- Compress HTML, CSS, JavaScript, Text, XML and fonts ##
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
@sarathlal-old
sarathlal-old / unzip.php
Last active November 26, 2015 05:12
Unzip .zip archive using PHP
<?php
// assuming file.zip is in the same directory as the executing script.
$file = 'mrkothari.zip';
// get the absolute path to $file
$path = pathinfo(realpath($file), PATHINFO_DIRNAME);
$zip = new ZipArchive;
$res = $zip->open($file);
if ($res === TRUE) {
@sarathlal-old
sarathlal-old / gist:3199a9a840cdbd39e7a1
Created December 3, 2015 12:54
Delete all Orders, Sales & Customer Data in Magento
SET FOREIGN_KEY_CHECKS=0;
##############################
# SALES RELATED TABLES
##############################
TRUNCATE `sales_flat_creditmemo`;
TRUNCATE `sales_flat_creditmemo_comment`;
TRUNCATE `sales_flat_creditmemo_grid`;
TRUNCATE `sales_flat_creditmemo_item`;
TRUNCATE `sales_flat_invoice`;
@sarathlal-old
sarathlal-old / mag_change_db_prefix.php
Last active February 10, 2016 04:16
Place this file in Magento installation root folder. Then change the database details & run the script. Last, change the database prefix in app/etc/local.xml.
<?php
//Add Database details
$database_host = "localhost";// DB Host
$database_user = "dbuser"; // DB User Name
$database_password = "dbpassword"; // DB Password
$magento_database = "dbname"; //DB Name
$table_prefix = "dbprefix_"; // DB Prefix
//Do the action
$db = mysql_connect($database_host, $database_user, $database_password);
import os, fnmatch
def findReplace(directory, filePattern):
for path, dirs, files in os.walk(os.path.abspath(directory)):
for filename in fnmatch.filter(files, filePattern):
filepath = os.path.join(path, filename)
with open(filepath) as f:
s = f.read().splitlines(True)
with open(filepath, "w") as f:
f.write("<?php")
f.writelines(s[1:])