Skip to content

Instantly share code, notes, and snippets.

@basvandorst
basvandorst / chunk_text_by_regex.py
Created April 4, 2024 08:56
Chunk a large text by a regex & nr of times the regex matches. Could be useful for text processing where you want to use the chunks for same regex as the tokenizer
import re
def chunk_text_by_regex(text, pattern, nr_matches):
prev = 0
chunks = []
for i, match in enumerate(re.finditer(pattern, text), start=1):
if i % nr_matches == 0:
chunks.append(text[prev:match.start()].strip())
prev = match.start()
if prev < len(text):
@basvandorst
basvandorst / portscan.py
Created February 14, 2018 15:08
Simple multithreaded portscanner
from threading import Thread
import socket
def scan(ip, port):
try:
con = socket.socket()
result = con.connect_ex((ip,port))
if result == 0:
print '[+] Port %d open' %port
@basvandorst
basvandorst / composer.json
Created November 1, 2016 14:23
php composer phpmd monolog phploc phpcpd phpcs
{
"description": "The ultimate toolbox of developer!",
"support": {
"basic_usage": "http://getcomposer.org/doc/01-basic-usage.md",
"packagist": "https://packagist.org/",
"phpqatools": "http://phpqatools.org/",
"helper": "http://composer.json.jolicode.com/"
},
"author": {
"name": "NerOcrO",
@basvandorst
basvandorst / kaggle_kfold.py
Last active September 13, 2016 14:05
Kaggle - House Prices
from sklearn.cross_validation import KFold
from sklearn import linear_model
from sklearn import ensemble
from sklearn.metrics import mean_squared_error
xpca = PCA(100).fit_transform(df_cars_maxabs);
kf = KFold(len(df), n_folds=10, shuffle=True)
@basvandorst
basvandorst / aivd-cyberchallenge
Last active December 3, 2016 15:47
AIVD Cyberchallenge 2015
#!/usr/bin/lua
--[[
AIVD Cyber challenge (https://www.aivd.nl/@3269/ga-cyberchallenge/)
bas@laptop:/var/www$ lua solve.lua
[*] ---------------------------------
[*] --- AIVD Cyber challenge 2015 ---
[*] ---------------------------------
[+] Start inverting number: 4241186467
@basvandorst
basvandorst / kappers_scraping.php
Last active August 29, 2015 14:16
kappers.nl scraping
<?php
// download @ http://sourceforge.net/projects/simplehtmldom/
require_once('simple_html_dom.php');
$cities = array(
'almere','amsterdam','rotterdam'
);
$total = 0;
foreach($cities as $city)
{
@basvandorst
basvandorst / huawei-find-password.py
Created August 8, 2014 12:45
Find the admin password of your Huawei DSL modem
#!/usr/bin/env python
# find-password.py
# Find the admin password of your Huawei DSL modem
#
# Author: Bas van Dorst
import optparse
import urllib2
import re
@basvandorst
basvandorst / Zend_Mail_InlineImages.php
Created August 21, 2012 13:48
Zend_Mail inline images in e-mail: CID attachment (tested in Gmail, Outlook.com, Outlook 2010)
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
@basvandorst
basvandorst / BolController.php
Created June 29, 2012 08:22
Example Zend Bol.com REST Controller
<?php
class BolController extends Zend_Controller_Action {
private function getSignature($date, $httpMethod, $url, $contentType, $queryParams) {
$signature = $httpMethod . "\n\n";
$signature .= $contentType . "\n";
$signature .= $date."\n";
$signature .= "x-openapi-date:" . $date . "\n";
$signature .= $url."\n";
@basvandorst
basvandorst / RegisterController.php
Created May 31, 2012 11:12
@maurice; Check this example of RegisterController.php with activateAction
<?php
class RegisterController extends Zend_Controller_Action {
public function init ()
{
$this->view->title = 'Register';
$this->view->menu = 'home';
}
public function indexAction() {