Skip to content

Instantly share code, notes, and snippets.

@adnanfajr
adnanfajr / nginx-express-socketio.conf
Last active August 4, 2017 09:20
nginx conf for Express JS and Socket IO on Ubuntu 16.04
server {
listen 80;
listen [::]:80;
server_name your-domain.name;
location / {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
<a href="javascript:doSomething();">
<script>
$(function(){
$( "#target" ).on("click",function(){
$("#successModal").modal();
});
});
</script>
@adnanfajr
adnanfajr / index.php
Last active July 29, 2016 00:25
Simple verification PHP
<?php
session_start();
if(!$_SESSION['logged']){
header("Location: signin.php");
exit;
}
// Setelah berhasil login
require_once 'php/config.php';
@adnanfajr
adnanfajr / dao.php
Last active June 25, 2016 15:04
PHP OOP PDO
<?php
// Database Access Object
class dao {
private $db = NULL;
private $connection_string = NULL;
private $db_type = DB_TYPE;
private $db_path = DB_PATH;
private $db_host = DB_HOST;
private $db_user = DB_USER;
@adnanfajr
adnanfajr / nginx conf for php
Created June 25, 2016 14:34
Nginx configuration for PHP applications. Copy at /etc/nginx/sites-available/domain.com
server {
listen 80;
#listen 80 default_server; if default server
root /var/www/DOMAIN;
index index.php index.html index.htm;
server_name DOMAIN.COM www.DOMAIN.COM;
if ($http_x_forwarded_proto = "http") {
@adnanfajr
adnanfajr / connection.py
Created June 25, 2016 14:25
Simple Python CRUD with MySQL
#!/usr/bin/python
import MySQLdb as mdb
import sys
try:
con = mdb.connect('localhost', 'USERNAME MYSQL', 'PASSWORD MYSQL', 'NAMA DATABASE');
cur = con.cursor()
cur.execute("SELECT VERSION()")
ver = cur.fetchone()
@adnanfajr
adnanfajr / PDO Query
Last active June 22, 2016 06:15
PHP PDO Configurations
<?php
require_once 'config.php';
/* QUERY SELECT */
$sql = "SELECT kurs FROM kurs WHERE valas = 'USD'";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$pkurs = $stmt->fetch(PDO::FETCH_ASSOC);
$post_kurs = $pkurs['kurs'];
@adnanfajr
adnanfajr / nginx conf for rails
Created April 17, 2016 11:21
Default nginx configuration for Rails in /etc/nginx/sites-available/default with Unicorn
upstream app {
# Path to Unicorn SOCK file, as defined previously
server unix:/var/www/APP_NAME/shared/sockets/unicorn.sock fail_timeout=0;
}
server {
listen 80;
#listen [::]:80 default_server ipv6only=on;
root /var/www/APP_NAME/public;
@adnanfajr
adnanfajr / nginx conf for https
Last active April 17, 2016 11:22
Nginx conf to enable https
...
if ($http_x_forwarded_proto = "http") {
return 301 https://$server_name$request_uri;
}
...