Skip to content

Instantly share code, notes, and snippets.

View gayanhewa's full-sized avatar
🦧
I may be slow to respond.

Gayan gayanhewa

🦧
I may be slow to respond.
View GitHub Profile
@gayanhewa
gayanhewa / QR.html
Created March 8, 2023 04:16
QR scanner
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>QR Code Scanner</title>
<style>
#video {
width: 100%;
height: auto;
}
@gayanhewa
gayanhewa / upload.php
Created October 5, 2014 16:44
PHP Script to upload files via FTP
<?php
// Ref : http://php.net/manual/en/function.ftp-put.php
$name = "test.txt";
$filename = "/home/mine/Desktop/test.txt";
//-- Code to Transfer File on Server Dt: 06-03-2008 by Aditya Bhatt --//
//-- Connection Settings
$ftp_server = "server_url_here"; // Address of FTP server.
$ftp_user_name = "username_here"; // Username
@gayanhewa
gayanhewa / express-basic-auth.js
Created May 23, 2022 13:52
Simple basic auth middleware with express-basic-auth
const app = require('express')()
const basicAuth = require('express-basic-auth')
var staticUserAuth = basicAuth({
users: {
'Admin': 'secret1234'
},
challenge: true,
})
@gayanhewa
gayanhewa / shopify-app-proxy-authenticated-route
Created March 6, 2022 22:12
Verify app proxy request if it came through Shopify or not
app.get("/app-proxy", async (req, res) => {
// Sorted list of query parameters
const q = {
path_prefix: req.query['path_prefix'],
shop: req.query['shop'],
timestamp: req.query['timestamp'],
};
const originalQuerystring = Object.keys(q).map(key => key + '=' + q[key]).join('');
const crypto = require('crypto')
@gayanhewa
gayanhewa / index.php
Created August 8, 2017 04:41
Visa Checkout Sample
<html>
<head>
<script type="text/javascript">
function createCookie(name,value,days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
@gayanhewa
gayanhewa / budget.ledger
Created July 31, 2019 20:52 — forked from tybl/budget.ledger
YNAB budgeting with ledger-cli
; This is a simple method of maintaining a budget using
; double-entry accounting software.
; Usually, double-entry accounting keeps track of
; assets, liabilities, income, and expenses. However,
; income/expense categories are different than budget
; categories. For one thing, income/expense categories
; continually grow, where budget categories tend to rise
; and fall. I decided to replace tracking my income/
; expenses with tracking my budget.
@gayanhewa
gayanhewa / signature.php
Created September 24, 2014 04:25
HMAC + Sha256 hashed API Auth - This snippet implements the logic behing https://github.com/philipbrown/signplz
<?php
/**
* This snippet implements the logic behing https://github.com/philipbrown/signplz , simply to explain the functionality of generating the auth signature
* for non-php programmers so that they can authenticate with the API without a problem.
**/
$api_key = "key";
$api_sec = "sec";
$url = "http://abc.com/api/test";
@gayanhewa
gayanhewa / rtl8821ae.conf
Created November 27, 2016 06:48
Realtek 8821ae driver config for linux. This avoids the connection drops for the 8821ae driver. Tested against debian jessie
options rtl8821ae debug=0 disable_watchdog=N fwlps=N swlps=Y swenc=Y ips=N msi=0
@gayanhewa
gayanhewa / default.site
Created September 6, 2020 23:37
deployd - default.site
server {
listen 80;
server_name example.com;
root /root/project/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.php;
@gayanhewa
gayanhewa / au_phone_validate
Created February 16, 2017 09:47
jquery validator australian phone number
jQuery.validator.addMethod("au_phone", function(value, element) {
return this.optional(element) || /^(?:\+?(61))? ?(?:\((?=.*\)))?(0?[2-57-8])\)? ?(\d\d(?:[- ](?=\d{3})|(?!\d\d[- ]?\d[- ]))\d\d[- ]?\d[- ]?\d{3})$/.test(value);
}, "Invalid phone number");