Skip to main content

Posts

Determine whether a given number can be expressed as sum of two prime numbers or not

/* Write a program to determine whether a given number can be expressed as sum of two prime numbers or not. For example 34 can be expressed as sum of two prime numbers but 23 cannot be. */ import java.util.*; import java.io.*; public class SumOfTwoPrime { public static void Primer(int num) { ArrayList<Integer> ar = new ArrayList<Integer>(); boolean flag=false; int prevPrime = 1; for(int i=1;i<=num;i++) { for(int j=2;j<i;j++) { if(i%j==0) { flag=false; break; } else flag=true; } if(flag==true) { ar.add(i); } } for(int i=0;i<ar.size();i++) { for(int j=0;j<ar.size();j++) { if( (ar.get(i))+(ar.get(j)) == num ) System.out.println(num+" is sum of two primes "+ar.get(i)+" and "+ar.get(j)); } } }   public static void main(String args[]) {   Scanner sc = new Scanner(System.in);   int n = sc.nextInt();   Primer(n);   } }...

Given a string, reverse only vowels in it; leaving rest of the string as it is

/* Given a string, reverse only vowels in it; leaving rest of the string as it is. Input : abcdef Output : ebcdaf */ import java.io.*; import java.util.*; public class VowelReverse { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); String vowels = ""; String ans = ""; int arr[] = new int[str.length()]; for(int i=0;i<str.length();i++) { if(str.charAt(i)=='a' || str.charAt(i)=='e' || str.charAt(i)=='i' || str.charAt(i)=='o' || str.charAt(i)=='u') { vowels+=str.charAt(i); arr[i]=1; } } String revVowels = new StringBuffer(vowels).reverse().toString(); int j=0; for(int i=0;i<str.length();i++) { if(arr[i]!=1) { ans+=str.charAt(i); } else { ans+=revVowels.charAt(j); j++; } } System.out.println(ans); } }

Making android apps easily within minutes

Hiii, I haven't been here for a while, after a long time i'm visiting my own blog 😀. Scan this QR code to download the app It has been changed a lot. Peoples are moving towards video blogs. Some peoples really don't have time to read a blogs. But I was really enjoyed writing since I started to blog. And I would like to share a lot with you friends. I will try to post at least one post per week 😂. I changed my blog name from mani-g to techfuu . And let's hope the numerology will help us to post frequently. 😇 Today we are going to see one amazing site that can help us to make our site content into an Android app. Interesting isn't. Within a few minutes we can get our android app ready to be published in google playstore. visit:  appsgeyser.com link to the app: http://app.appsgeyser.com/5083322/Tech%20fu register there and give your site url. Within few minutes it will send the apk with source code to our mail. To publish our app to google pla...

speeding up and saving data in chrome browser

Here in India we don't afford an unlimited internet plan or high speed internet(mostly). I came through some awesome chrome extensions to the rescue. I checked most of the extension they work seamlessly in my chrome browser in ubuntu 14.04. If you're using windows you can consider an awesome ucbrowser that forked from chromium web browser. that support all the extensions of google chrome browser. we can grab it from  pc.ucweb.com . It as its own cloud compression technology known as speedmode that can reduce the data transmitted over internet. Check it yourself. So, here are the chrome extensions used to reduce internet data. 1. Google data saver extension: You may seen this on your android devices, and now it's available for pc version of chrome. It uses the google's own server to optimize the pages that we request. It will not work with SSL or HTTPS sites. and it works damn nice with ordinary sites. grab it here:  data-saver-beta  and it's currently a bet...

First Graphic program in C

Current semester i have a Computer Graphics as a subject. Here is my first program that implements the bresenham's circle drawing algorithm to draw a circle and with some lines i created a smiley : ) #include "stdio.h" #include "graphics.h" void brecircle(xc,yc,r) { int x,y,p; x=0; y=r; putpixel(xc+x,yc-y,1); p=3-(2*r); for(x=0;x<=y;x++) { if (p<0) { y=y; p=(p+(4*x)+6); } else { y=y-1; p=p+((4*(x-y)+10)); } putpixel(xc+x,yc-y,15); putpixel(xc-x,yc-y,15); putpixel(xc+x,yc+y,15); putpixel(xc-x,yc+y,15); putpixel(xc+y,yc-x,15); putpixel(xc-y,yc-x,15); putpixel(xc+y,yc+x,15); putpixel(xc-y,yc+x,15); } } int main() { int x,y; int gd = DETECT, gm=0; initgraph(&gd,&gm,""); x=getmaxx()/2; y=getmaxy()/2; brecircle(x,y,150); brecircle(x-50,y-50,19); brecircle(x+50,y-50,19); line(x,y,x+20,y+20); line(x,y,x-20,y+20); line(x-20,y+20,x+20,y+20); line(x-40,y+50,x+40,y+50); getch(); closegraph(); return 0; } ...

wordpuzzle solver

Most of the *nix systems contains the wordlist. This script will use that wordlist to search the words for the given pattern. #!/usr/bin/python import re import sys if len(sys.argv[:]) != 2: print "usage: ./puzzle.py 'pattern'" exit(0) pattern = sys.argv[1] length = len(pattern) pattern = pattern.replace('?','\w') words = open('/usr/share/dict/words','r') print '' for word in words: if len(word)== int(length)+1 and re.search(pattern,word): print word.strip() Also made a gui for that application You can get the full source code for this app in  https://github.com/manimaran990/wordpuzzle

Pronunciation script in python

Frequently i had a visits to google to search for some word pronunciations. So I wrote this small script to save my time. you need to install mpg123 before you run this script by $ sudo apt-get install mpg123 spellit.py #!/usr/bin/python import os import sys url = 'http://ssl.gstatic.com/dictionary/static/sounds/de/0/' if len(sys.argv[:]) != 2: print 'usage: ./spellit.py word' exit(0) word = sys.argv[1] final = url+word+'.mp3' os.system('mpg123 -q %s'% final)

Sneak-peek at py-qt

Learned some py-qt to build a front-end for the sms api #!/usr/bin/python import sitsms import sys from PyQt4 import QtGui, QtCore class Sitsms(QtGui.QWidget): def __init__(self): super(Sitsms, self).__init__() self.initUI() def initUI(self): number = QtGui.QLabel("Number ",self) number.move(20,20); message = QtGui.QLabel("Message ",self) message.move(20,60); self.numberEdit = QtGui.QLineEdit(self) self.numberEdit.resize(190,24); self.numberEdit.move(80,20); self.messageEdit = QtGui.QTextEdit(self) self.messageEdit.resize(220,200) self.messageEdit.move(80,60); self.sendbtn = QtGui.QPushButton("send",self) self.sendbtn.setStyleSheet("QPushButton:pressed { background-color: green }" "QPushButton:released { background-color: gray }" ) quitbtn = QtGui.QPushButton("Exit",...

My First Applicaiton in Rails

Here is my gpa calculator app in rails.   cgpacalc.herokuapp.com with some bootstrap. It calculates the gpa and allow users to signup and save their marksheets for their future references. some vim tips: I used vim editor for this development.  There is a plugin called vim-rails  it can make the development much easier. vi editor should be on your box. need to install vim-pathogen  before installing vim-rails mkdir -p ~/.vim/autoload ~/.vim/bundle; \ curl -LSso ~/.vim/autoload/pathogen.vim \ https://raw.github.com/tpope/vim-pathogen/master/autoload/pathogen.vim then add this on .vimrc file execute pathogen#infect() after that we can install vim-rails by cd ~/.vim/bundle git clone git://github.com/tpope/vim-rails.git git clone git://github.com/tpope/vim-bundler.git open vim and type :Rails Baisc commands: :Rmodel user :Rcontroller application :Rhelper navigation :Rview sessions/new :Rfunctionaltest sessions :Runittest user

GPA calculator in RUBY

#!/usr/bin/env ruby =begin Prgram : CGPA calculator Date : May 16, 2014 Author : ManiG License : GPL2.0 Version : 1.0 =end sum=0.0 grade = {"S"=>10,"A"=>9,"B"=>8,"C"=>7,"D"=>6,"E"=>5,"U"=>0} tot_credits = 0 tot_egrades = 0 print "enter no. of subjects : " sub_count = gets().to_i sub_count.times do |c| print "enter subject#{c+1}'s credit : " credit = gets().to_i tot_credits += credit print "enter subject#{c+1}'s earned grade :(only 'S','A','B','C','D','E','U') : " e_grade = gets().chomp.upcase tot_egrades += grade[e_grade] sum += grade[e_grade]*credit end gpa = sum/tot_credits puts puts "Credits Earned #{tot_credits}" puts "Grade points earned #{tot_egrades}" puts "GPA #{format("%.4f",gpa)}" puts "CGPA #{format("%.4f",g...

ARP/RARP full simulation program

server.c #include "stdio.h" #include "stdlib.h" #include "string.h" #include "sys/types.h" #include "sys/socket.h" #include "arpa/inet.h" #include "netinet/in.h" #define SA struct sockaddr struct IPmac { char ip[100]; char mac[100]; }; int main() { int sockfd,len,i; struct sockaddr_in servaddr; char buff[30],temp[30],ip[30],mac[30];

FTP simulation to read the file contents

server.c #include "stdio.h" #include "string.h" #include "sys/types.h" #include "sys/socket.h" #include "arpa/inet.h" #include "netinet/in.h" #define SA struct sockaddr int main(int argc,char** argv) { int sockfd; int n=0,clilen; char fname[20],content[2000],ch; FILE *fp; struct sockaddr_in servaddr,cliaddr; if(argc!=2) { printf("usage ./server PORT\n"); return 0; }

UDP echo server, client

udpserver.c #include "stdio.h" #include "stdlib.h" #include "sys/types.h" #include "sys/socket.h" #include "arpa/inet.h" #include "netinet/in.h" #include "string.h" #define SA struct sockaddr #define MAX 1024 int main(int argc,char** argv) { int sockfd,n; socklen_t len; struct sockaddr_in servaddr,cliaddr; char buff[MAX],tmp[MAX]; //create socket sockfd = socket(AF_INET,SOCK_DGRAM,0);

This Week's Experiments

Experimenting LEOXSYS-nano wifi adapter: Recently bought this tiny wifi adapter from flipkart. Making this wifi-adapter able to work is wont be problem under windows. But in LINUX it need some patience. Linux Kernel doesn't have the supportive drivers to make it workable on linux. Thank god they gave one small disc which contains the drivers for this wifi-adapter. Inside the disk there are various folders and finally found one Linux folder in it. Make sure you copy that into your home directory not to any others. (We are going to make it and install it. It needs a folder permission to execute some utility programs) then make it and install it, and it works just fine in my LinuxMint 14. Soon to register for a wifi connection in my campus :-) Making Balance enquiry of the usb modem from Terminal This one is my favourite trick to know the balance amount of my 3g dongle. All you need is one tiny little program called gammu.

Simulation of ARP/RARP

Here is the core simulation of the ARP(Address Resolution Protocol) and RARP(Reverse Address Resolution Protocol) ARP used to map the ip address with the corresponding MAC address and RARP do that in reverse. it maps the MAC with the ip. #include "stdio.h" #include "string.h" int main() { char table[3][2][40]; char ipin[10],macin[30]; int i,j,found; strcpy(table[0][0],"127.0.0.1"); strcpy(table[0][1],"44:dd:22:11:33"); strcpy(table[1][0],"10.1.1.8"); strcpy(table[1][1],"33:aa:fe:4e:2d"); strcpy(table[2][0],"10.1.8.5"); strcpy(table[2][1],"23:a3:5d:33:9d"); printf("IP address\t MAC address\n"); for(i=0;i

Workshop on IBM BIGDATA

Here is my shell script which i wrote to make the process of installing the IBM biginsight (hadoop) on the lab. My team installed the hadoop using this script for around 70 systems, it saved lots of time for us, and we successfully conducted the workshop on it today. #!/bin/bash #generating keygen for the root user with no password ssh-keygen -f $HOME/.ssh/id_rsa -t rsa -N '' echo "key generated in $HOME" #append it to the authorized_keys cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys echo "appended to authorized_keys" #create a usergroup

Cipher engine in ruby

Recently i have started to learn ruby because it's the core language for the rails framework. Here the cipher engine which uses the old caesar cipher algorithm, i have used file concepts to read and write the both encrypted and decrypted outputs to files. We can also use other methods separately, launch your irb then load 'encryptor.rb' make an instance of the Encryptor class by e = Encryptor.new to check all the available methods e.methods

tcp client, server chat simplified

Here is my simplified version of the tcp client, server chat application client.c #include "stdio.h" #include "stdlib.h" #include "sys/types.h" #include "sys/socket.h" #include "arpa/inet.h" int main() { int sockfd,n; char buff[256]; struct sockaddr_in servaddr; //create socket sockfd = socket(AF_INET,SOCK_STREAM,0); //fill serv struct servaddr.sin_family = AF_INET; servaddr.sin_port = htons(40402); servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");

Executing external programs via c

import time print time.ctime() this snippet will print the system time. in my networking lab, i used this python snippet to print the system time. actually i have to write a client, server program in c to achieve this. but i have found a lazy way. when mam ask us to show the output i planned to run this python snippet :) (don't tell her); only problem is i cannot make it as an executable code. ./timecli