Skip to content

Instantly share code, notes, and snippets.

View staskobzar's full-sized avatar
🖥️
Nulla dies sine linea

Stas Kobzar staskobzar

🖥️
Nulla dies sine linea
  • ClearlyIP
  • Montreal
View GitHub Profile
key:
field: data
sub:
data: value
another:
sous: data
nested:
sub: information
foo: bar
static int token_type(enum yaml_token_type_e yaml_token)
{
switch(yaml_token)
{
case YAML_NO_TOKEN : return 0;
case YAML_STREAM_START_TOKEN : return STREAM_START;
case YAML_STREAM_END_TOKEN : return STREAM_END;
case YAML_BLOCK_MAPPING_START_TOKEN : return BLOCK_MAPPING_START;
case YAML_BLOCK_END_TOKEN : return BLOCK_END;
@staskobzar
staskobzar / libyaml_lemon-05.mk
Last active September 24, 2017 02:10
libyaml_lemon Makefile
LDLIBS = -lyaml
all: main
main: main.o parser.o
parser.c: parser.y
lemon $^
.PHONY: clean
/* Read tokens */
while(1) {
if (!yaml_parser_scan(&parser, &token)) {
printf("ERROR: Parsing failed.\n");
retval = EXIT_FAILURE;
goto done;
}
if (token.type == YAML_BLOCK_END_TOKEN ||
token.type == YAML_FLOW_SEQUENCE_END_TOKEN ||
const char *token_type_str[] = {
"YAML_NO_TOKEN",
/** A STREAM-START token. */
"YAML_STREAM_START_TOKEN",
/** A STREAM-END token. */
"YAML_STREAM_END_TOKEN",
/** A VERSION-DIRECTIVE token. */
"YAML_VERSION_DIRECTIVE_TOKEN",
@staskobzar
staskobzar / libyaml_lemon-sample-02.yaml
Last active September 21, 2017 01:42
Libyaml and lemon blog #02
receipt: Oz-Ware Purchase Invoice
date: 2012-08-06
customer:
first_name: Dorothy
family_name: Gale
items:
- part_no: A4786
descrip: Water Bucket (Filled)
price: 1.47
@staskobzar
staskobzar / libyaml_lemon-main-01.c
Last active September 21, 2017 22:23
Libyaml and lemon blog #01
#include <stdio.h>
#include <stdlib.h>
#include <yaml.h>
int main(int argc, const char *argv[])
{
FILE *file;
yaml_parser_t parser;
yaml_token_t token;
int retval = EXIT_SUCCESS;
#include <ruby.h>
#include "url_parser.h"
static VALUE host_type (enum host_type type)
{
VALUE htype;
switch (type)
{
case REGNAME:
htype = rb_to_symbol (rb_str_new2 ("REGNAME"));
require 'spec_helper'
require 'url_parser'
describe UrlParser::URL do
context 'valid URL' do
subject (:url){ UrlParser::URL.new('https://alice:secret@example.com:80/path/index.php?filter=employee#first_name') }
it { is_expected.to be_valid }
describe "#scheme" do
it { expect(url.scheme).to eql 'https' }
end
@staskobzar
staskobzar / opensips-ide-invite-req.pl
Created March 16, 2014 17:51
Example of intrusion detection with OpenSIPS for INVITE requests (http://staskobzar.blogspot.ca/2014/03/opensips-intrusion-detection.html)
if (is_method("INVITE")) {
if(cache_fetch("redis","user:$fU",$avp(authpass))){
$avp(authuser) = $fU;
if(!pv_proxy_authorize("")) {
xlog("L_INFO","$ci|$rm| Challeng proxy auth for user $avp(authuser)");
# store tries for 30 sec
# each new try would increase expire to another 30 sec
cache_add("redis", "auth:$fU:tries",1,30);
# check if limit of tries reached
cache_counter_fetch("redis","auth:$fU:tries", $var(tries));