Skip to content

Instantly share code, notes, and snippets.

View krlicmuhamed's full-sized avatar

Muhamed Krlić krlicmuhamed

  • IMASoft
  • Bosnia and Herzegovina
View GitHub Profile
@krlicmuhamed
krlicmuhamed / base64.prg
Last active July 22, 2022 13:03
Decode a base64 string in FoxPro
FUNCTION DECSTR64
PARAMETERS S
LOCAL i,j,j,k,q,ch,s2,buf,tmpc
tmpc = 0
j = 0
buf = 0
s2 = ''
k = LEN(s)
FOR i = 1 TO k
ch = ASC(SUBSTR(s,i,1))
@krlicmuhamed
krlicmuhamed / regex.prg
Last active March 19, 2021 19:12
Using regex in FoxPro
oRE = CreateObject("VBScript.RegExp")
oRE.Pattern = "regular expression here"
lcString = "string to search"
llResult = oRE.test(lcString)
lcMatches = oRE.Execute(lcString)
IF ALEN(lcMatches) > 0
llResult = lcMatches(0).Submatches(0) && First match and first submatch/group
ENDIF
@krlicmuhamed
krlicmuhamed / httpmessagebuilder.prg
Last active December 11, 2021 12:00
Build HTTP Request Messages using Visual FoxPro
*Example Usage:
CLEAR
Builder = CREATEOBJECT('HttpMessageBuilder')
*Builder.UserAgent = 'BK5'
Builder.AddHeader('TestHeader', 'test123 456')
Builder.AddHeader('TestHeader', 'test123 456')
Builder.AddParameter('TestParameter', 'Thisisat estparameter')
Builder.AddParameter('TestParameter', 'Thisisatestparam eter')
* You also get a free URLEncode function :)
Builder.URLEncode('str in g <3')
@krlicmuhamed
krlicmuhamed / crc.c
Created August 16, 2016 15:22
CRC16 Calculation
unsigned short crc_16_rec(unsigned char * pucData, unsigned short ucLen) {
//--------------------------------------------------------------------
unsigned int i;
unsigned char ucBit, ucCarry;
//--------------------------------------------------------------------
unsigned short usPoly = 0x8408; //reversed 0x1021
unsigned short usCRC = 0;
//--------------------------------------------------------------------
for (i = 0; i < ucLen; i++) {
usCRC ^= pucData[i];
@krlicmuhamed
krlicmuhamed / actions_securityApiKey.js
Last active August 12, 2016 22:56
Simple API KEY security using ActionHero and Redis
'use strict';
var uuid = require('node-uuid');
exports.action = {
name: 'securityApiKey', // Internal security action. Do not change the name.
description: 'I hand out api keys.',
version: 1.0,
inputs: {
uniqueId: {
required: true,
validator: function(param, connection, actionTemplate){
@krlicmuhamed
krlicmuhamed / protobuf.js
Last active July 15, 2016 20:25
actionhero socket server with fast protobuf serializer
var net = require('net');
var tls = require('tls');
var path = require('path');
var protobuf = require('protocol-buffers');
var initialize = function(api, options, next) {
var type = 'protobuf';
var attributes = {
pendingShutdownWaitLimit: 5000,
schema: require('fs').readFileSync(path.join(__dirname, 'schema.proto')).toString()
//Lets require/import the HTTP module
var http = require('http');
//Lets define a port we want to listen to
const PORT=8080;
//We need a function which handles requests and send response
function handleRequest(request, response){
response.end('It Works!! Path Hit: ' + request.url);
}
@krlicmuhamed
krlicmuhamed / request_html.js
Created October 3, 2015 10:42
Get HTML content from the internet
var s = require('net').Socket();
s.connect(80, 'google.com');
s.write('GET http://www.google.com/ HTTP/1.1\n\n');
s.on('data', function(d){
console.log(d.toString());
});
s.end();
@krlicmuhamed
krlicmuhamed / pgsql_function_example.sql
Created August 29, 2015 13:05
An example of postgres function ( stored procedure ) that returns a query.
CREATE OR REPLACE FUNCTION stored_get_data_history(SPGroupID integer, FromDate timestamp with time zone, ToDate timestamp with time zone)
RETURNS TABLE (device_id integer, "location" geometry, accuracy DOUBLE PRECISION, speed DOUBLE PRECISION, azimuth DOUBLE PRECISION, "createdAt" timestamp with time zone) LANGUAGE PLPGSQL AS $$
BEGIN
RETURN QUERY SELECT
"Data".device_id,
"Data".location,
"Data".accuracy,
"Data".speed,
"Data".azimuth,
"Data"."createdAt"