Skip to content

Instantly share code, notes, and snippets.

@kcabading
kcabading / useTimer.ts
Created August 4, 2023 16:51
React hook for using Timer with Milliseconds
import { useState, useRef } from "react";
const Timer = ( initial: number, ascending: boolean) => {
const [ms, setMs] = useState(initial * 100)
const [timesUp, setTimesUp] = useState<boolean>(false)
const intervalRef = useRef<number>()
function convertMSTimeToString (ms: number){
const minutes = String(Math.floor( ms / 100 / 60)).padStart(2, '0')
@kcabading
kcabading / deploy.sh
Created February 28, 2018 12:00
Bash script for deploying Wordpress using Jenkins and Bitbucket.
#!/bin/bash
# PLACEHOLDERS
# [STAGING_FOLDER] - staging directory in your server
# [STAGING_URL] - staging url
# [STAGING_USER] - staging user in the server
# [STAGING_MYSQLUSER] - staging mysql user
# [STAGING_MYSQLPASSWORD] - staging mysql password
# [ROOTUSER] - Mysql root user
# [ROOTPASSWORD] - Mysql root password
@kcabading
kcabading / .gitignore
Created February 6, 2018 11:27
Bare gitignore file for Wordpress for Gobro
# -----------------------------------------------------------------
# .gitignore for WordPress
# Bare Minimum Git
# http://ironco.de/bare-minimum-git/
# ver 20150227
#
# This file is tailored for a WordPress project
# using the default directory structure
#
@kcabading
kcabading / gist:3fe0d6026f8dda7210838fd07837b748
Created February 21, 2017 08:43
Initialising select2 in sugarcrm sidecar with options to load default list using an app_strings_list or from module's records.
({
_render: function() {
// load default options using app strings
this._setSelectField("element_id_here", "", app.lang.getAppListStrings("cstm_lead_source_list") , false, null, null, null);
// if you want to load default selected value
$('#element_id_here').select2('val','id_in_the_option_list');
// load options from records of a module
this._setSelectField("element_id_of_the_field", "", null, "Accounts", "name", this.getPersonRecordList);
},
getPersonRecordList: function(strName, strModule, fieldname, callback) {
@kcabading
kcabading / joi-parse-validation.js
Created February 21, 2017 08:31
JS helper to Parse validation errors and messages returned by https://github.com/hapijs/joi
'use strict';
const _ = require('lodash');
const parseReason = function (message) {
const regexBecause = /because \[(.*?)(\]|$)/;
let parsedMessage = message;
if (regexBecause.test(message)) {
parsedMessage = regexBecause.exec(message)[1];