Skip to content

Instantly share code, notes, and snippets.

View paralax's full-sized avatar

jose nazario paralax

View GitHub Profile
@paralax
paralax / DBN_example.fs
Created March 9, 2016 20:21
DeepBeliefNetwork in F#
#r "Debug/Accord.dll"
#r "Debug/Accord.Math.dll"
#r "Debug/Accord.Neuro.dll"
#I "Debug"
// based on C# from http://whoopsidaisies.hatenablog.com/entry/2014/08/19/015420
open Accord.Neuro
open Accord.Neuro.Networks
open Accord.Neuro.Learning
@paralax
paralax / ngram_classifier.fs
Last active May 2, 2017 21:08
working on classifying stuff via ngrams
// https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence
let KullbackLeiblerD (p : Map<string,int>) (q : Map<string,int> ) : double =
// pp and qq are ngram frequencies
let pp = Map.toList p |> List.map snd |> List.sum |> float
let qq = Map.toList q |> List.map snd |> List.sum |> float
let Q (i:string) (q : Map<string,int>) : double =
// retrieves the frequency of i in q if found or returns .00001
match (Map.tryFind i q) with
| Some(x) -> float(x)/qq
@paralax
paralax / fizzbuzz_in_DBN.fsx
Last active January 12, 2018 10:37
i ported that "fizzbuzz in tensorflow" to F# and Accord.Net's DeepBeliefNetwork
// i ported that "fizzbuzz in tensorflow" to F# and Accord.Net's DeepBeliefNetwork
// http://joelgrus.com/2016/05/23/fizz-buzz-in-tensorflow/
#r "Debug/Accord.dll"
#r "Debug/Accord.Math.dll"
#r "Debug/Accord.Neuro.dll"
#I "Debug"
open Accord.Neuro
open Accord.Neuro.Networks
@paralax
paralax / threatcrowd_api.fs
Last active August 8, 2016 13:58
ThreatCrowd API via F#
open System
open System.IO
open System.Text
// https://github.com/JamesNK/Newtonsoft.Json/releases
open Newtonsoft.Json
open Newtonsoft.Json.Linq
// from http://www.fssnip.net/8j
/// Log levels.
@paralax
paralax / VZBlatencies.fs
Created September 4, 2016 22:05 — forked from anonymous/VZBlatencies.fs
small HTML table scraper and demo in F#
open System
open System.Net
open System.Text
// https://social.msdn.microsoft.com/Forums/en-US/5a26bb89-c0e4-4ca4-b0c7-220c5fe1f495/how-to-get-a-html-table-using-regex?forum=regexp
(*
let table_pattern = "<table.*?>(.*?)</table>"
let tr_pattern = "<tr.*?>(.*?)</tr>"
let td_pattern = "<td.*?>(.*?)</td>"
@paralax
paralax / alga.fs
Created December 31, 2016 03:05
implementation of basic algebra for graphs
// https://blogs.ncl.ac.uk/andreymokhov/an-algebra-of-graphs/
type Vertex = string
type Graph(vertices:Set<Vertex>, edges:Set<(Vertex * Vertex)>) =
member this.vertices = vertices
member this.edges = edges
member this.empty() = new Graph(Set.empty, Set.empty)
member this.overlay(g:Graph) = new Graph(Set.union this.vertices g.vertices, Set.union this.edges g.edges)
@paralax
paralax / hmm_baumwelchlearning.fs
Created February 3, 2017 14:43
Hidden Markov Model in F# using Accord Framework and Baum Welch Learning
// based on this example http://accord-framework.net/docs/html/T_Accord_Statistics_Models_Markov_Learning_BaumWelchLearning.htm
open System
open Accord.Math
open Accord.Statistics.Models.Markov.Learning
open Accord.Statistics.Models.Markov
let sequences = [|
[| 0;5;3;2;5;2|];
@paralax
paralax / divergence_measures.fs
Created May 4, 2017 19:55
towards implementing the Jensen-Shannon divergence metric, IEEE TRANSACTIONS ON INFORMATION THEORY. VOL. 37, NO. I, JANUARY 1991
let entropy (s) : float =
let p = string(s).ToCharArray()
|> Seq.groupBy (fun x -> x)
|> Seq.map (fun (x,y) -> Seq.length y)
-1.0 * ([ for count in p ->
float(count)/float(String.length(s)) *
System.Math.Log(float(count)/float(String.length(s)), 2.0) ]
|> Seq.sum )
let ngrams (s : string) (n: int) : Map<string,int> =
@paralax
paralax / Makefile
Last active July 2, 2024 01:40
vtwebd - a very tiny web daemon that servers static content
all: vtwebd
request.o: request.c
gcc -g -O2 -c request.c
vtwebd.o: main.c
gcc -pthread -g -O2 -c main.c
vtwebd: vtwebd.o request.o
gcc -pthread -g -o vtwebd main.o request.o
@paralax
paralax / tcp_banner_grab.php
Last active June 1, 2018 16:16
TCP connect() scanner with banner grab
<?php
$ports = range(20, 100);
$IP = "192.168.1.50";
$results = array();
foreach ($ports as $port) {
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array('sec'=>0, 'usec'=>100));
socket_set_option($sock, SOL_SOCKET, SO_SNDTIMEO, array('sec'=>0, 'usec'=>100));
if (@socket_connect($sock, $IP, $port)) {
socket_recv($sock, $buffer, 1024, 0);