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 / DNS prefetching
Created August 25, 2016 04:56
Common Prefetch Links
<!-- Amazon S3 -->
<link rel="dns-prefetch" href="//s3.amazonaws.com">
<!-- Google CDN -->
<link rel="dns-prefetch" href="//ajax.googleapis.com">
<!-- Microsoft CDN -->
<link rel="dns-prefetch" href="//ajax.microsoft.com">
<link rel="dns-prefetch" href="//ajax.aspnetcdn.com">
from bs4 import BeautifulSoup
import urllib
f = open('jan.csv','w')
for i in range(120,130):
openurl = 'http://192.168.1.64/demo/test/fold/'+str(i)+'.html'
r = urllib.urlopen(openurl).read()
soup = BeautifulSoup(r)
title = soup.find("div", class_="row1 content conAddres").find("h3").string
from bs4 import BeautifulSoup
import urllib
r = urllib.urlopen('http://192.168.1.64/test/120.html').read()
soup = BeautifulSoup(r)
title = soup.find("div", class_="row1 content conAddres").find("h3").string
author = soup.find("div", class_="row1 content conAddres").find("h4").find("a").string
@sarathlal-old
sarathlal-old / copy-website.sh
Created June 19, 2016 14:45
Copy sequential web pages and save as file using curl
#!/bin/bash
for i in {3142..3150}
do
curl -A 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12' -o $i.html http://targetsite.com/posts/$i/
done
@sarathlal-old
sarathlal-old / add-text.php
Last active June 2, 2016 12:43
Add string on each line of a file content before or after the content. Just insert the file to be processed on the same directory in our server and call our script via browser.
<?php
$handle = fopen("file.txt", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
// process the line read.
echo "Text Before - " . $line . " - Text After<br>";
}
fclose($handle);
} else {
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:])
@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);
@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 / 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 / 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