Skip to content

Instantly share code, notes, and snippets.

View lifeparticle's full-sized avatar
🥥
0, 1, 2, 3…

Mahbub Zaman lifeparticle

🥥
0, 1, 2, 3…
View GitHub Profile
@lifeparticle
lifeparticle / count.java
Last active December 17, 2015 05:49
Count the unique character in a String
// Author: Mahbub
// http://mahbubzaman.wordpress.com/2012/06/21/count-the-unique-character-in-a-string/
/*
input
“aaaaaa”
“aaa aaa”
“abcdeabcde”
“YESyes”
output
@lifeparticle
lifeparticle / README.md
Last active December 17, 2015 05:49
HOW TO CHECK EFFICIENTLY IF A NUMBER IS PRIME OR NOT

A number is a prime number if that number has precisely two distinct divisors, one and itself. First ten prime numbers are

2, 3, 5, 7, 11, 13, 17, 19, 23, 29

So, if we can find that N has two divisors than it’s a prime number else not, this is actually brute force approach and the complexity is O (N). How we do that, starting from 1 to N we have check if N is divisible by 1, 2, 3, ….., N each time it divide we increment our divisor count by one and at the end we will check if the divisor count is 2 or not.

Can we do better, yes we can. Look carefully the only even prime is 2. If we add an if condition that if the number is 2 return true else false if the number is even, because other even numbers can’t not be a prime number. For even numbers the complexity becomes O (1). So what about odd numbers? How can we improve that? We can reduce the complexity for odd number O (N / 2). See we don’t need to divide by even numbers because the Number N is an odd number, so it will never be divide by an even number. So

@lifeparticle
lifeparticle / genPrime.html
Last active December 17, 2015 18:29
Randomly Generates primes from first 100 using Javascript
<!-- Author: Mahbub -->
<h1 id="prime">2</h1>
<p>is a prime number</p>
<!-- Randomly Generates primes from first 100 -->
<script>
var primes=[-1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163 ,167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541];
var index = Math.floor((Math.random() * (primes.length - 1)) + 1);
if (index >= 1 && index <= (primes.length - 1))
document.getElementById("prime").innerHTML = primes[index];
@lifeparticle
lifeparticle / README.md
Last active September 14, 2022 01:26
This python script will list your public and private gist.

List git gist

This script will print the output in HTML format on stdout. Console command

$ python list_your_gitgist.py > out.html

@lifeparticle
lifeparticle / BUG.md
Last active December 18, 2015 20:39
Grameen Phone weird bug

Interesting bug

Mou icon

while testing our app Easy Recharge, Version two, i saw this weird bug.

##Information

  • Android version: 4.1.1
  • Sim: Grameen Phone
@lifeparticle
lifeparticle / Get Old Month Using Time Class
Last active December 26, 2015 10:48
Android Time Class
// Author: Mahbub
// http://mahbubzaman.wordpress.com/2013/10/24/android-time-class/
/*
http://developer.android.com/reference/android/text/format/Time.html
just provide the month, year and day and get previous dates
Since Time class does not provides months and day name, you have to do that by yourself
*/
@lifeparticle
lifeparticle / টার্মিনাল কমান্ড বাংলায় (Termianl Commands in Bangla)
Last active August 29, 2015 13:56
টার্মিনাল কমান্ড বাংলায় (Termianl Commands in Bangla)
// Author Shouro and Mahbub
// 24 February, 2014
alias লিস্ট='ls'
alias ঢুকি='cd'
alias দেখ='vim'
alias কপি='cp'
alias মুছ='rm'
alias পুস্তিকাবানাও='mkdir'
#!/usr/bin/env python
# beta
# Lisence Under GPL2
# Author: S.Mahbub-Uz-Zaman
import fnmatch
import os
def count_lines(filePath):
@lifeparticle
lifeparticle / replace.java
Created April 13, 2015 22:21
Replace last occurrence of Character in a String using Java
// beta
// Lisence Under GPL2
// Author: S.Mahbub-Uz-Zaman
public static String a = "test,test,test";
public static String replaceWith = " and ";
// using StringBuffer's replace method
public static void replaceLastCommaSB () {
StringBuffer sb = new StringBuffer(a);