Skip to content

Instantly share code, notes, and snippets.

View napsternxg's full-sized avatar
🎯
Focusing

Shubhanshu Mishra napsternxg

🎯
Focusing
View GitHub Profile
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author napsternxg
*/
function returnFirstPostImage($id){
global $wpdb;
$the_content =$wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID = $id");
$pattern = '!<img.*?src="(.*?)"!';
preg_match_all($pattern, $the_content, $matches);
$image_src = $matches['1'][0];
@napsternxg
napsternxg / MultiExtensionFind.sh
Created August 10, 2012 12:55
Find all files with .c, .h and .pm extension in a given folder
find ./ -name \*.[ch] -print -o -name \*.pm -print
@napsternxg
napsternxg / countFiletypes.sh
Created September 6, 2012 20:27
Count all file types in a directory recursively
find ./ -type f | grep -E ".*\.[a-zA-Z0-9]*$" | sed -e 's/.*\(\.[a-zA-Z0-9]*\)$/\1/' | sort | uniq -c | sort -n | tee filetype1.list
@napsternxg
napsternxg / largestPrimeFactor.py
Created September 23, 2012 21:57
Code to find all the prime factors of a large number
"""
The original code for the following program was written by Sangam Kumar Jain and can be found in the file test.py in this git project
You can connect with him at: http://www.facebook.com/jain.sangam
The code was written as a part of solving Project Euler Problem 3 (http://projecteuler.net/problem=3) which deals with finding the largest prime factor of a large number.
Currently the code finds all the powers of all prime factors of any large number.
I have rewritten a more modular and optimized version of the above code and tried to make it more easily comprehendable.
@napsternxg
napsternxg / simulateMatrix.sh
Created October 1, 2012 10:26
Create Matrix Dropping Numbers Effect
echo -e "\e[32m"; while :; do printf '%*c' $(($RANDOM % 5)) $(($RANDOM % 7)); done
@napsternxg
napsternxg / reverseWordsInString.py
Created October 7, 2012 21:01
Reverse the order of all the words in a given string
str = "This is a beautiful world"
" ".join(reversed(str.split(" ")))
@napsternxg
napsternxg / countLines.sh
Created October 15, 2012 12:56
Count all the number of times a line occurs in a file ignoring case
cat sample | sort -f | uniq -ci | sort -n | sed -e 's/\([0-9]\{1,\}\)[ ]*\(.*\)/\2: \1/g'
@napsternxg
napsternxg / FindFullPath.sh
Created October 18, 2012 10:51
Find all full fill paths in a file having strings
# syncFiles is a file name you can also use any command like ls, p4 sync ... instead of cat syncFiles
cat syncFiles | cut -f 2 -d "-" | sed -e 's/\([A-Za-z0-9 ]*\)\([\/\.A-Za-z0-9_]*\)\([A-Za-z0-9 ]*\)/\2/g'
@napsternxg
napsternxg / collectStackExchangeData.js
Created October 23, 2012 09:10
Collect data containing sitename, total(questions, answers, comments, tags) on the page: http://data.stackexchange.com/
//collect data containing sitename, total(questions, answers, comments, tags) on the page: http://data.stackexchange.com/
data = [];
$(".site-list > li").each(function(){
obj = {};
obj.name = $(this).find("img").attr("alt");
obj.totalQ = $(this).find(".totalQuestions > .pretty-short").attr("title");
obj.totalA = $(this).find(".totalAnswers > .pretty-short").attr("title");
obj.totalC = $(this).find(".totalComments > .pretty-short").attr("title");