Skip to content

Instantly share code, notes, and snippets.

View subhanshuja's full-sized avatar
🏠
Working from home

Subhan Nooriansyah subhanshuja

🏠
Working from home
View GitHub Profile
@prime31
prime31 / gist:5675017
Last active April 2, 2024 03:55
Simple PHP script showing how to send an Android push notification. Be sure to replace the API_ACCESS_KEY with a proper one from the Google API's Console page. To use the script, just call scriptName.php?id=THE_DEVICE_REGISTRATION_ID
<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'YOUR-API-ACCESS-KEY-GOES-HERE' );
$registrationIds = array( $_GET['id'] );
// prep the bundle
$msg = array
@dorelljames
dorelljames / laravel-nginx-config-make-http-exception-url-and-make-all-others-https.md
Last active December 18, 2023 10:05
Laravel nginx config to redirect all requests to https and an exception URL that can still be accessible via http

Pre-condition

One day in your Laravel app, you were required to redirect all http requests to https but need to make a certain URL route accessible via http for a certain reason; perhaps a portion of your javascript code needs to redirect to http URL but it can't because redirection to secure URL to insecure is prohibited. Therefore, in cases like this, you need to just allow just one URL to make an http connection.

NOTE: There are obvious security implications here so don't just follow this blindly and understand if this is really the solution you're looking for. The nginx config can somehow be improved, I just don't have the time yet. It sure do look redundant.

Understanding and examples

  • Redirect everything from http to https
@hrwgc
hrwgc / validate.sh
Created November 13, 2013 19:57
bash wget - check if file exists at url before downloading
#!/bin/bash
# simple function to check http response code before downloading a remote file
# example usage:
# if `validate_url $url >/dev/null`; then dosomething; else echo "does not exist"; fi
function validate_url(){
if [[ `wget -S --spider $1 2>&1 | grep 'HTTP/1.1 200 OK'` ]]; then echo "true"; fi
}
@BrandonSmith
BrandonSmith / AndroidManifest.xml
Last active July 19, 2023 19:11
Quick example of how to schedule a notification in the future using AlarmManager
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cards.notification">
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
@goblindegook
goblindegook / wordpress.nginxconf
Last active February 14, 2023 21:05
Nginx virtual host configuration for WordPress
server {
listen 80;
server_name www.example.com;
rewrite ^ $scheme://example.com$request_uri?;
}
server {
listen 80;
server_name example.com;
@subhanshuja
subhanshuja / laravel-nginx-config-make-http-exception-url-and-make-all-others-https.md Laravel nginx config to redirect all requests to https and an exception URL that can still be accessible via http

Pre-condition

One day in your Laravel app, you were required to redirect all http requests to https but need to make a certain URL route accessible via http for a certain reason; perhaps a portion of your javascript code needs to redirect to http URL but it can't because redirection to secure URL to insecure is prohibited. Therefore, in cases like this, you need to just allow just one URL to make an http connection.

NOTE: There are obvious security implications here so don't just follow this blindly and understand if this is really the solution you're looking for. The nginx config can somehow be improved, I just don't have the time yet. It sure do look redundant.

Understanding and examples

  • Redirect everything from http to https
@subhanshuja
subhanshuja / Account.php
Last active November 26, 2020 05:15
Abstract Class User in Php
<?php
declare(strict_types=1);
$path = dirname(__DIR__, 1);
$path .= '/models/UserModel.php';
require_once $path;
class Account extends User {
private $userId;
@subhanshuja
subhanshuja / domodernjs.sh
Last active November 10, 2020 09:29
download file modern js without npm using bash
#ref: https://gist.github.com/hrwgc/7455343
function validate_url(){
if [[ `wget -S --spider $1 2>&1 | grep 'HTTP/1.1 200 OK'` ]]; then echo "true"; fi
}
# file list of url
file="listlib.txt"
while IFS= read -r line; do
if `validate_url $line > /dev/null`; then wget $line -P /path/lib/; else echo "doesn't exist"; fi
@subhanshuja
subhanshuja / ineventhandler.kt
Last active June 30, 2020 08:14
Sever Sent Event (SSE)
interface DefaultEventHandler : EventHandler {
@Throws(Exception::class)
override fun onOpen() {
Log.i("open","open")
}
@Throws(Exception::class)
override fun onClosed() {
Log.i("close","close")
@saggafarsyad
saggafarsyad / android-serviceToast.java
Last active August 5, 2019 14:51
Android - Show Toast from Service
// If you Service with threads, e.g. a Chat Service
// You want to show a toast such as indicating the connection is lost or stuff when your service is running foreground
// Get main the main thread, you are only allowed to draw UI in the main thread
Handler mainHandler = new Handler(getMainLooper());
mainHandler.post(new Runnable() {
@Override
public void run() {
// Do your stuff here related to UI, e.g. show toast