Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Shubhanshu Mishra napsternxg

🎯
Focusing
View GitHub Profile
View ObjectOperations.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author napsternxg
*/
View Wordpress-GetFirstPostImage.php
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 Aug 10, 2012
Find all files with .c, .h and .pm extension in a given folder
View MultiExtensionFind.sh
find ./ -name \*.[ch] -print -o -name \*.pm -print
@napsternxg
napsternxg / countFiletypes.sh
Created Sep 6, 2012
Count all file types in a directory recursively
View countFiletypes.sh
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 Sep 23, 2012
Code to find all the prime factors of a large number
View largestPrimeFactor.py
"""
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 Oct 1, 2012
Create Matrix Dropping Numbers Effect
View simulateMatrix.sh
echo -e "\e[32m"; while :; do printf '%*c' $(($RANDOM % 5)) $(($RANDOM % 7)); done
@napsternxg
napsternxg / reverseWordsInString.py
Created Oct 7, 2012
Reverse the order of all the words in a given string
View reverseWordsInString.py
str = "This is a beautiful world"
" ".join(reversed(str.split(" ")))
@napsternxg
napsternxg / countLines.sh
Created Oct 15, 2012
Count all the number of times a line occurs in a file ignoring case
View countLines.sh
cat sample | sort -f | uniq -ci | sort -n | sed -e 's/\([0-9]\{1,\}\)[ ]*\(.*\)/\2: \1/g'
@napsternxg
napsternxg / FindFullPath.sh
Created Oct 18, 2012
Find all full fill paths in a file having strings
View FindFullPath.sh
# 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 Oct 23, 2012
Collect data containing sitename, total(questions, answers, comments, tags) on the page: http://data.stackexchange.com/
View collectStackExchangeData.js
//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");