Skip to content

Instantly share code, notes, and snippets.

View hu2di's full-sized avatar

Huy-Hung Dinh hu2di

View GitHub Profile
@hu2di
hu2di / Rate.java
Last active May 3, 2018 13:13
Android: Intent Review App
final String appPackageName = getActivity().getPackageName(); // from Context
try {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
@hu2di
hu2di / ChatBot.js
Created April 10, 2017 02:49
Server chat with Node.js and Socket.IO
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
//Include .html file
app.get('/', function(req, res) {
//res.send('<h1>Hello World</h1>');
res.sendFile(__dirname + '/index.html');
});
@hu2di
hu2di / GetContent.java
Created April 10, 2017 02:49
Android: Get content form URL
private static String docNoiDung_Tu_URL(String theUrl) {
StringBuilder content = new StringBuilder();
try {
URL url = new URL(theUrl);
URLConnection urlConnection = url.openConnection();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String line;
while ((line = bufferedReader.readLine()) != null) {
content.append(line + "\n");
}
@hu2di
hu2di / MyConnection.java
Created April 10, 2017 02:48
Android: Check connection
public static boolean isInternetConnection(Context context) {
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null)
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
@hu2di
hu2di / ImageLoader.java
Created April 10, 2017 02:46
Android: Image Loader - AsyncTask
public class ImageLoadTask extends AsyncTask<String, Void, Bitmap> {
@Override
protected Bitmap doInBackground(String... params) {
private String url = params[0];
try {
//Tiến hành tạo đối tượng URL
URL urlConnection = new URL(url);
//Mở kết nối
HttpURLConnection connection = (HttpURLConnection) urlConnection
.openConnection();
@hu2di
hu2di / TestLib.cpp
Created April 10, 2017 02:45
C++: lib
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int n;
int a[10001];
void input(){
@hu2di
hu2di / SaveObj.java
Created April 10, 2017 02:44
Android: Saving Object on External Storage
//<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
public void ReadFile() {
try {
File f = new File(filename);
FileInputStream fIn = context.openFileInput(f.getPath());
ObjectInputStream oIn = new ObjectInputStream(fIn);
myPost = (ArrayList<Status>) oIn.readObject();
oIn.close();
fIn.close();
@hu2di
hu2di / Inherit.cs
Created April 10, 2017 02:43
C-sharp: Subclass doesn't inherit constructors of its parent class.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Constructor
{
class Program
{
@hu2di
hu2di / Convert.cs
Created April 10, 2017 02:42
C-sharp: Convert
int n;
n = int.Parse(Console.ReadLine());
double sum = 0.0;
for (int iCount = 1; iCount <= n; iCount++)
{
sum = sum + 1 / iCount;
}
Console.WriteLine("Ket qua: {0}", sum);
@hu2di
hu2di / Print.cpp
Created April 10, 2017 02:40
printf - function isn't safe
#include<stdio.h>
int main()
{
char input[200];
while(1)
{
printf("\n\n");
gets(input);
printf(input);
}