Skip to content

Instantly share code, notes, and snippets.

View omaraflak's full-sized avatar
👨‍💻
hey you

Omar Aflak omaraflak

👨‍💻
hey you
View GitHub Profile
@omaraflak
omaraflak / Downloader.java
Last active February 28, 2017 13:04
Download file asynchronously with listener for progress in Android
package me.aflak.youtubedownloader.model;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
@omaraflak
omaraflak / tcp-chat-server.js
Last active April 26, 2016 15:42
net server in nodejs to forward messages.
var net = require('net');
var sockets = [];
var svr = net.createServer(function(sock) {
console.log('Connected: ' + sock.remoteAddress + ':' + sock.remotePort);
sockets.push(sock);
sock.write('Welcome to the server!');
sock.on('data', function(data) {
@omaraflak
omaraflak / Client.java
Last active April 30, 2016 08:32
Socket class for Android that can be used with a NodeJS server.
public class Client {
private Socket socket;
private OutputStream socketOutput;
private BufferedReader socketInput;
private String ip;
private int port;
private ClientCallback listener=null;
public Client(String ip, int port){
@omaraflak
omaraflak / MainActivity.java
Last active April 24, 2016 23:57
MediaPlayer Android from URL
// DON'T FORGET IN MANIFEST: <uses-permission android:name="android.permission.INTERNET" />
try {
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource("http://server.com/music.mp3");
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
@omaraflak
omaraflak / Tool.java
Last active February 19, 2018 23:37
Image convolution with kernel
public class Tool {
static double[][][] loadImage(String path){
BufferedImage image;
try {
image = ImageIO.read(new File(path));
double[][][] imageMatrix = new double[3][image.getHeight()][image.getWidth()];
int color, red, green, blue;
for (int i=0 ; i<image.getHeight() ; i++){
for (int j=0 ; j<image.getWidth() ; j++){
@omaraflak
omaraflak / main.cpp
Last active November 6, 2024 12:42
Image convolution in C++ + Gaussian blur
#include <iostream>
#include <vector>
#include <assert.h>
#include <cmath>
#include <png++/png.hpp>
using namespace std;
typedef vector<double> Array;
typedef vector<Array> Matrix;
@omaraflak
omaraflak / ShakeDetector.java
Last active March 18, 2017 13:42
Listener for shake events.
/**
* Created by Omar on 07/03/2017.
*/
public class ShakeDetector implements SensorEventListener {
private static final int SENSITIVITY = 18;
private static final int INTERVAL_M = 2500;
private SensorManager sensorManager;
private Sensor accelerometer;
@omaraflak
omaraflak / ObjectSaver.java
Last active August 6, 2017 16:32
Small wrapper for shared preferences.
// build.gradle
// implementation 'com.google.code.gson:gson:2.8.1'
public class ObjectSaver {
private static SharedPreferences sharedPreferences;
private static Resources resources;
private static Gson gson;
public static void init(Context context) {
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
package me.aflak.test;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
@omaraflak
omaraflak / main.c
Last active September 2, 2017 12:06
Minesweeper in C for Windows
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <stdbool.h>
char **board;
char **displayedBoard;
const char BOMB = 'X';