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
//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 / 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()
@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 / 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 / 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 / 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 / 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))