Skip to content

Instantly share code, notes, and snippets.

View voidnerd's full-sized avatar
:octocat:
Debugging

Ndifreke Friday voidnerd

:octocat:
Debugging
View GitHub Profile
@voidnerd
voidnerd / closure_table.md
Created September 14, 2018 16:25
Persistent tree structure using closure table in MySQL

Using closure tables to manage hierarchical relations in MySQL

Create DB tables

Create a table to represent tree nodes.

CREATE TABLE `tree_node` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `data_body` text,

node_deleted datetime DEFAULT NULL,

@voidnerd
voidnerd / build-tree.php
Created September 17, 2018 13:52 — forked from vyspiansky/build-tree.php
PHP: convert object / array to tree structure
<?php
/*
* Source: http://goo.gl/p2GybZ
*/
// for object
function buildTree($items) {
$childs = array();
foreach($items as $item)
@voidnerd
voidnerd / html5-video-streamer.js
Created October 2, 2018 16:22 — forked from paolorossi/html5-video-streamer.js
Node.js HTML5 video streamer
/*
* Inspired by: http://stackoverflow.com/questions/4360060/video-streaming-with-html-5-via-node-js
*/
var http = require('http'),
fs = require('fs'),
util = require('util');
http.createServer(function (req, res) {
var path = 'video.mp4';
@voidnerd
voidnerd / fileupload.js
Last active December 20, 2018 16:05
A sample file upload using Javascrip
// example html
<input type="file" id="upload" style="display:none" name="upload">
<button id="clik"> Click to Upload Video</button>
//Start Upload
function _(el) {//helper function
return document.getElementById(el);
}
@voidnerd
voidnerd / no-try-catch-async-await.js
Created April 22, 2019 12:46 — forked from DavidWells/no-try-catch-async-await.js
Nicer try/catch for async await.
/* Helper buddy for removing async/await try/catch litter 🗑 */
function O_o(promise) {
return promise.then(data => {
if (data instanceof Error) return [data]
return [null, data]
}).catch(err => [err])
}
/* Look ma, no try/catch */
async function usageExample(params) {
@voidnerd
voidnerd / resetrootpassword.md
Last active August 24, 2021 07:59
reset mysql (5.7) root password on ubuntu 19.04

Step 1

sudo /etc/init.d/mysql stop

Step 2

sudo mkdir /var/run/mysqld/
const axios = require('axios');
const secretKey = "<PAYSTACK_SECRET_KEY>"
const initializePaystack = async (form) => {
const options = {
url : 'https://api.paystack.co/transaction/initialize',
create database if not exists `worktern`;
CREATE TABLE `users` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`first_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`last_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`email_verified_at` timestamp NULL DEFAULT NULL,
<?php
function verify($reference) {
$result = array();
//The parameter after verify/ is the transaction reference to be verified
//you have to get reference from callback url if you are using paystack standard
$url = 'https://api.paystack.co/transaction/verify/'. $reference;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://js.paystack.co/v1/inline.js"></script>
</head>