Skip to content

Instantly share code, notes, and snippets.

View ano's full-sized avatar
🏠
Working from home

Anonga Tisam ano

🏠
Working from home
View GitHub Profile
@ano
ano / phpmaker.sync.lib.php
Last active May 5, 2018 05:44
A library for PHPMaker that enables one to many relationships between forms in Machform
<?php
/*
CUSTOM_CODE
-----------
Author: Ano Tisam
Date: 09/03/2015
Description: Machform customisation to keep lookup fields [checkbox, select, radio] in Child_Forms in sync with data in Parent_Forms
Essentialy mimicing 1:M relational database features in Machform between forms.
Requires PHPMaker, sync.lib.php library, database created by ap_custom_link.sql file.
*/
@ano
ano / linkify.js
Last active April 7, 2019 07:30
Detect and Convert text URLs into clickable links
// Detect and Convert URL's into clickable links
function linkify(link, text) {
var urlRegex =/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
return link.replace(urlRegex, function(url, text) {
return '<a href="' + url + '">'+ text +'</a>';
});
}
// Usage
linkify("https://www.google.com", "Search");
@ano
ano / slugify.js
Created July 9, 2018 23:47
Create a slug from string in Javascript
function string_to_slug(str) {
str = str.replace(/^\s+|\s+$/g, ""); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
var from = "åàáãäâèéëêìíïîòóöôùúüûñç·/_,:;";
var to = "aaaaaaeeeeiiiioooouuuunc------";
for (var i = 0, l = from.length; i < l; i++) {
str = str.replace(new RegExp(from.charAt(i), "g"), to.charAt(i));
@ano
ano / compare.tables.js
Last active August 11, 2018 03:11
Compares two tables and highlights the changes. The two tables MUST have two columns; the first column is for the name, and the second column is for the value.
/*
* Demo: https://codepen.io/anonga/full/XBOpJq
* Example Usage:
#html
<table id="left">...</table>
<table id="right">...</table>
@ano
ano / write.sql.functions.php
Last active August 12, 2018 00:14
Machform: Write an sql query for a given form_id
<?php
/*
* FORM FUNCTIONS
Usage:
# hooks/sql/index.php
//Load machform files
define("BASE_PATH", "../../")
@ano
ano / machform-password-generator.php
Last active October 12, 2018 00:06
Machform password generation service. Facilitates user integration with Zapier and / or other services
<?php
/*
Desciption: Machform password generation service for integration with Zapier
Author: Ano Tisam
Organisation: WHUPI LTD
Website: https://www.whupi.com/
Date: 12/10/2014
*/
define("BASE_PATH", "../../../"); //Relative PATH to MACHFORMS ROOT FOLDER
require(BASE_PATH . 'includes/filter-functions.php');
@ano
ano / vessel.json
Created October 30, 2018 06:25
A demo JSON Schema for Vessel
{
"$id": "https://standards.ffa.int/vessel.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "The representation of a vessel",
"type": "object",
"title": "Vessel",
"properties": {
"vessel_name": {
"title": "Vessel Name",
"type": "string",
@ano
ano / redux_business_modeller_admin_theme.json
Created November 13, 2018 01:05
Admin Theme for Business Modeller
{
"last_tab":"9",
"dynamic-css-type":"custom",
"primary-color":"#f45246",
"page-bg":{
"background-color":"#f0f1f2",
"background-repeat":"",
"background-size":"",
"background-attachment":"",
"background-position":"",
@ano
ano / contains-word.php
Created January 31, 2019 19:50
A PHP function to check if a sentence contains a specific word?
<?php
function contains_word($str, $word)
{
return !!preg_match('#\\b' . preg_quote($word, '#') . '\\b#i', $str);
}
//usage
$a = 'How are you?';
@ano
ano / machform_autocomplete.js
Last active November 17, 2021 19:32
Machform: Add autocomplete to a textbox based on previously entered values
/*
* Example Usage
*/
$(document).ready(function(){
var autocomplete_options = {
base: "http://localhost/platform/forms/v11/hooks/api/v2/index.php/", //Base path of the API
form: "ap_form_11330", //The form you are searching
element: "element_1", //The field to search
skip: "element_60", //The field you skip auto population
staticFilters: "order=date_created%2Cdesc&page=1%2C10&transform=true", //Other static filters to apply, see here https://github.com/mevdschee/php-crud-api#list--filter