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
@luthfihariz
luthfihariz / NewsActivity.java
Created December 7, 2012 15:52
Submenu with Action Bar Sherlock
//here code before...
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.article_menu, menu);
return super.onCreateOptionsMenu(menu);
}
public boolean onOptionsItemSelected(
@luthfihariz
luthfihariz / ListItem.java
Created December 30, 2012 02:59
Loading newsfeed in background
package com.ideaplay.sharee.utility;
import java.util.ArrayList;
public class ListItem {
private String contributorImageUrl;
private String itemTitle;
private String itemContent;
private String itemContributor;
private String itemPubDate;
@mlbright
mlbright / slidingwindowmap.py
Created September 5, 2012 03:35
Solution to the SlidingWindowMap coding challenge by Cedric Beust
# solution to http://beust.com/weblog/2012/09/02/coding-challenge-a-sliding-window-map/
import heapq
import time
class SlidingWindowMap(object):
def __init__(self,api_keys,max_count,period_minutes):
self.period = period_minutes * 60
self.pq = []
for api_key in api_keys:
@subhanshuja
subhanshuja / adam_lbfgs_compare.py
Created December 27, 2017 03:30 — forked from glennq/adam_lbfgs_compare.py
Benchmarks for learning rate updating schemes in MLP
import numpy as np
from time import time
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
from sklearn.cross_validation import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import make_moons, make_circles, make_classification
from sklearn.neural_network import MLPClassifier
@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
@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")
@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 / 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 / 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
@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;