Skip to content

Instantly share code, notes, and snippets.

@Abdelhady
Abdelhady / DeviceOrientation
Last active April 29, 2023 05:16
A utility class to help get current device orientation, you will need it if you decided to fix the activity's orientation in the manifest :)
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.media.ExifInterface;
/**
* Created by abdelhady on 9/23/14.
*
* to use this class do the following 3 steps in your activity:
@Abdelhady
Abdelhady / EmailCampaignParameters.php
Last active January 29, 2017 13:26
Use this utility function to append GA's campaign (or any other parameters with a small modification) to all links in your email at once, in an efficient way which uses `DOMDocument::loadHTML` instead of using custom regex.
<?php
/**
* appending campaign parameters to every single link `<a href=''></a>`
* in the given $bodyHtml
*
* @param type $bodyHtml
*/
public function appendCampaignPrameters($bodyHtml, $utmCampaign) {
$newParams = [
@Abdelhady
Abdelhady / FileController.php
Last active November 16, 2018 16:36
Traditional way of uploading files
<?php
class FileController {
public function postAction() {
// Disable views/layout the way suites your framework
if (!isset($_FILES['imageFile'])) {
// Throw an exception or handle it your way
}
// Nginx already did all the work for us, & received the file in the `/tmp` folder
$uploadedFile = $_FILES['imageFile'];
$OriginalFileName = $uploadedFile['name'];
@Abdelhady
Abdelhady / TusController.php
Last active November 17, 2018 01:04
Initial Tus implementation
<?php
class TusController {
public function indexAction() {
// Disable views/layout the way suites your framework
$server = new TusPhp\Tus\Server(); // Using File Cache (over Redis) for simpler setup
$server->setApiPath('/tus/index') // tus server endpoint.
->setUploadDir('/tmp'); // uploads dir.
$response = $server->serve();
@Abdelhady
Abdelhady / TusController.php
Created November 17, 2018 00:26
Tus implementation - Final version
<?php
class TusController {
public function indexAction() {
// Disable views/layout the way suites your framework
$server = $this->_getTusServer();
$response = $server->serve();
$this->_fixNonSecureLocationHeader($response);
$response->send();
@Abdelhady
Abdelhady / AppHelper.java
Last active March 14, 2020 13:18 — forked from anggadarkprince/AppHelper.java
Upload file with Multipart Request Volley Android - Supporting UTF-8 Encoding
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import java.io.ByteArrayOutputStream;
/**
* Sketch Project Studio
* Created by Angga on 12/04/2016 14.27.
*/
public class AppHelper {