Skip to content

Instantly share code, notes, and snippets.

View chathudan's full-sized avatar

Chathura Wijesinghe chathudan

View GitHub Profile
@chathudan
chathudan / AutoResizeTextView.java
Last active June 17, 2021 11:31
Text view that auto adjusts text size to fit within the view. If the text size equals the minimum text size and still does not fit, append with an ellipsis.
import android.content.Context;
import android.text.Layout.Alignment;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.widget.TextView;
/**
* Text view that auto adjusts text size to fit within the view.
@chathudan
chathudan / SMSReceiver.java
Last active June 17, 2021 11:32
Android SMS Receive Listener
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import java.util.ArrayList;
/**
* @@author Chathura Wijesinghe <cdanasiri@gmail.com>
@chathudan
chathudan / GitTips.md
Last active August 29, 2015 14:19
Git Tips

create a new git branch from an old commit

This will create the new branch and check it out.

git checkout -b development a9c146a09505837ec03b

This development the branch without checking it out.

git branch development a9c146a09505837ec03b

Rollback to an old commit using

@chathudan
chathudan / TurnServerInstallationDocumentation.md
Last active April 4, 2020 11:55
Turn Server Installation Documentation

Turn Server Installation Documentation

change the package according to your server

wget http://turnserver.open-sys.org/downloads/v3.2.4.4/turnserver-3.2.4.4-debian-wheezy-ubuntu-
mint-x86-64bits.tar.gz

tar -zxvf turnserver-3.2.4.4-debian-wheezy-ubuntu-mint-x86-64bits.tar.gz

wget http://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
public static class TrustedSSLSocketFactory extends SSLSocketFactory {
SSLContext sslContext = SSLContext.getInstance("TLS");
public TrustedSSLSocketFactory(KeyStore truststore)
throws NoSuchAlgorithmException, KeyManagementException,
KeyStoreException, UnrecoverableKeyException {
super(truststore);
TrustManager tm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain,
@chathudan
chathudan / RecordingActivity.java
Last active January 21, 2024 09:53
Android Audio recording, MediaRecorder example
/**
* @author Chathura Wijesinghe <cdanasiri@gmail.com> on 9/9/15.
*/
public class RecordingActivity extends AppCompatActivity implements View.OnClickListener {
private TextView mTimerTextView;
private Button mCancelButton;
private Button mStopButton;
private MediaRecorder mRecorder;
@chathudan
chathudan / BackupRestoreMySQLDatabase.md
Last active July 21, 2021 09:46
Back Up and Restore a MySQL Database

If you're storing anything in MySQL databases that you do not want to lose, it is very important to make regular backups of your data to protect it from loss. This tutorial will show you two easy ways to backup and restore the data in your MySQL database. You can also use this process to move your data to a new web server.

Back up From the Command Line (using mysqldump)

Back up your MySQL Database with Compress

Restoring your MySQL Database

Backing Up and Restoring using PHPMyAdmin

free -m to see memory statistics

df -h to see disk usage statistics

du -h --max-depth=1 | sort -hr

ls -ld .?* Will only list hidden files

ls -a List All Files

@chathudan
chathudan / xpub-xsub.js
Created October 30, 2017 07:22 — forked from tjanczuk/xpub-xsub.js
How to connect 5 publishers with 5 subscribers over TCP using ZeroMQ's XPUB/XSUB proxy
// How to connect 5 publishers with 5 subscribers
// over TCP using ZeroMQ's XPUB/XSUB proxy.
// sub (connect)
// <-8701->
// (bind) xpub <---> xsub (bind)
// <-8700->
// (connect) pub
var zmq = require('zmq');
@chathudan
chathudan / mediaqueries.css
Created January 24, 2019 07:04 — forked from needim/mediaqueries.css
Device Specific CSS Media Queries Collection
/*
Based on:
1. http://stephen.io/mediaqueries
2. https://css-tricks.com/snippets/css/media-queries-for-standard-devices/
*/
/* iPhone X in portrait & landscape */
@media only screen
and (min-device-width : 375px)
and (max-device-width : 812px)