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 / টার্মিনাল কমান্ড বাংলায় (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);
/**
* Author S Mahbub-Uz Zaman on October 23, 2015
* Lisence Under GPL2
*/
public static String monthNames[] = {"January", "February", "March", "April",
"May", "June", "July", "August", "September", "October",
"November", "December"};
// input 17/06/1991
@lifeparticle
lifeparticle / cus_view.xml
Created November 7, 2015 17:19
apply layout_weight in a xml object so that it will have 20% of height and 80% of width
/**
* Author S Mahbub-Uz Zaman on November 8, 2015
* Lisence Under GPL2
*/
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
@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 / 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 / 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 / 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