Skip to content

Instantly share code, notes, and snippets.

View frhan's full-sized avatar

Farhan Faruque frhan

View GitHub Profile
@frhan
frhan / android_viewpager_dynamic
Created January 1, 2014 21:01
Android dynamic view pager
After figuring out which ViewPager methods are called by ViewPager and which are for other purposes, I came up with a solution. I present it here since I see a lot of people have struggled with this and I didn't see any other relevant answers.
First, here's my adapter; hopefully comments within the code are sufficient:
class MainPagerAdapter extends PagerAdapter
{
// This holds all the currently displayable views, in order from left to right.
private ArrayList<View> views = new ArrayList<View>();
//-----------------------------------------------------------------------------
public class OpenPdf extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.OpenPdfButton);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@frhan
frhan / DeviceListActivity.java
Last active August 29, 2015 13:56
Bluetooth discovery android
package com.sel.code;
import java.util.Set;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
Even if you haven't tracked the files so far, git seems to be able to "know" about them even after you add them to .gitignore.
A quick fix that I've used was to run the following commands from the top folder of your git repo:
(edited)
git rm -r --cached .
Followed by:
git add .
and
@frhan
frhan / mongo_db_reapir
Created August 22, 2014 17:50
Reapir mongodb
Step 1: Remove lock file.
sudo rm /var/lib/mongodb/mongod.lock
Step 2: Repair mongodb.
mongod --repair
Step 3: start mongodb.
sudo start mongodb
or
sudo service mongodb start
@frhan
frhan / android_custom_action_bar
Created September 23, 2014 22:19
custom action bar for android
private void setCustomActionbar()
{
actionBar.setLogo(null); // forgot why this one but it helped
View homeIcon = findViewById(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ?
android.R.id.home : android.support.v7.appcompat.R.id.home);
((View) homeIcon.getParent()).setVisibility(View.GONE);
((View) homeIcon).setVisibility(View.GONE);
@frhan
frhan / android_hide_soft_keyboard
Created September 23, 2014 23:15
android- hide sof keyboard
public void hideSoftKeyboard()
{
InputMethodManager inputManager = (InputMethodManager)
getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
View v = getActivity().getCurrentFocus();
if(v == null)
return;
inputManager.hideSoftInputFromWindow(v.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
public void setCurrentWithClearTop(Class<?> klass,Bundle b)
{
Intent intentToBeNewRoot = new Intent(this, klass);
ComponentName cn = intentToBeNewRoot.getComponent();
Intent mainIntent = IntentCompat.makeRestartActivityTask(cn);
startActivity(mainIntent);
}
@frhan
frhan / edit and add var-www
Last active September 28, 2022 00:07
the simplest way to edit and add files to “/var/www”
if you make /var/www writeable by its group and add the user to the group, that user will not have to use sudo. Try this:
sudo adduser <username> www-data
sudo chown -R www-data:www-data /var/www
sudo chmod -R g+rw /var/www
The user should then be able to edit /var/www/ files without hassle.
The first line adds the user to the www-data group, the second line clears up any files with messed up ownership, and the third makes it so that all users who are members of the www-data group can read and write all files in /var/www.
If you are logged in as <username> you need to log out and log back in for the group membership to take effect.
@frhan
frhan / ealyH.markdown
Last active August 29, 2015 14:08
A Pen by Farhan Faruque.