Skip to content

Instantly share code, notes, and snippets.

View crushcafeteria's full-sized avatar

Nelson Ameyo crushcafeteria

  • Nairobi, Kenya
View GitHub Profile
@crushcafeteria
crushcafeteria / cart.php
Last active June 3, 2016 11:13
BlackPay Express Hookup
<?php
# Generate a sample the payload structure
$payload = array(
'store_id' => '10',
'cart_id' => '#234-14-222-KY', # May be an invoice number
'cart_items' => array(
array(
'id' => 'SKU-123-145',
'name' => 'Sony Playstation 2',
'qty' => 1,
function ip_recieve(){
header('Content-Type: application/json');
# Save transaction
$data = $this->input->post();
# Clean up a bit
$data['till_no'] = $data['business_number'];
$data['provider'] = 'KOPOKOPO';
@crushcafeteria
crushcafeteria / Apache2 SSL Virtual Host - Sample
Created April 20, 2016 12:05
How to set up an SSL virtual host with Apache2 and LetsEncrypt CA
# Redirect non-SSL traffic to SSL site
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
Redirect permanent / https://example.com/
</VirtualHost>
# SSL Site
<VirtualHost *:443>
ServerAdmin [email protected]
<?php
# Final storage for the products our script
# will send to BlackPay for billing
$cartItems = array(); # or [], who cares?
# Get an array of all items the customer has
# placed in the shopping basket
$basket = $this->getShoppingBasketContents('basket_uuid');
# If the previous array has extra information, you can
@crushcafeteria
crushcafeteria / default.conf
Created June 29, 2017 08:16
Sample Nginx Laravel Server Block
server {
listen 80 default_server;
root /var/www/laravel/public;
index index.php index.html index.htm;
server_name _;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /index.php = 404;
@crushcafeteria
crushcafeteria / escrow.php
Last active July 23, 2017 13:49
Escrow API example
<?php
# Collect relevant data from your backend systems
$transaction = [
'telephone' => '0700123456',
'action' => 'BUY',
'product_name' => 'Nike Shoes',
'price' => 5000,
'description' => 'Hello World!',
];
@crushcafeteria
crushcafeteria / image-preview.js
Created October 15, 2017 19:27
Snippet - Preview image in file upload field with HTML 5
// Preview image
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('.propertyImagePreview').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
@crushcafeteria
crushcafeteria / kenyan-counties.php
Created March 8, 2018 07:43
PHP array of all the 47 counties of Kenya. Useful for populating dropdowns
<?php
#############################################################
# 47 counties of Kenya #
#############################################################
$config['counties'] = [
'BARINGO' => 'Baringo County',
'BOMET' => 'Bomet County',
'BUNGOMA' => 'Bungoma County',
'BUSIA' => 'Busia County',
'ELGEYO-MARAKWET' => 'Elgeyo-Marakwet County',