Skip to content

Instantly share code, notes, and snippets.

@jaysoncena
jaysoncena / pyspark-apache-logs.py
Created March 10, 2016 13:43
PySpark code to analyze Tomcat logs (can be also used with Apache HTTPd logs)
%pyspark
import re
from pyspark.sql.types import *
from pyspark.sql import Row
from datetime import datetime
access = "ABCD"
@jaysoncena
jaysoncena / parallel_exec.sh
Created March 19, 2016 05:35
Execute list of commands in parallel with limit on the number of concurrent commands
#!/bin/bash -x
OLD_IFS="${IFS}"
IFS="
"
LIMIT=2
cmd_buff="`cat command_list.txt`"
declare -a cmd_list=($cmd_buff)
@jaysoncena
jaysoncena / get-started-by-user.groovy
Created April 18, 2016 09:25
Jenkins - Get the user who triggered the current or the parent job
def triggeredBy = "---"
def iterateCause(b) {
upstreamcause = b.getCause(hudson.model.Cause.UpstreamCause.class)
if (upstreamcause != null) {
job = Jenkins.getInstance().getItemByFullName(upstreamcause.getUpstreamProject(), hudson.model.Job.class)
if (job != null) {
upstream = job.getBuildByNumber(upstreamcause.getUpstreamBuild())
if (upstream != null) {
iterateBuild(upstream)
@jaysoncena
jaysoncena / tcpdump_advanced_filters.txt
Created April 5, 2017 03:12
tcpdump advance filters
# From https://www.wains.be/pub/networking/tcpdump_advanced_filters.txt
tcpdump advanced filters
========================
Sebastien Wains <sebastien -the at sign- wains -dot- be>
http://www.wains.be
###################################################################
This page is not updated anymore and contains mistakes and typos.
Please check the updated link:
@jaysoncena
jaysoncena / config
Created September 10, 2018 12:29
ssh client config
Host users.ncl.sg
User jcena096
LocalForward 5901 n1.network2.CS4238-18-01.ncl.sg:5901
LocalForward 5902 n2.network2.CS4238-18-01.ncl.sg:5902
LocalForward 11002 n1.network2.CS4238-18-01.ncl.sg:11002
LocalForward 11003 n1.network2.CS4238-18-01.ncl.sg:11003
LocalForward 11004 n1.network2.CS4238-18-01.ncl.sg:11004
LocalForward 11005 n1.network2.CS4238-18-01.ncl.sg:11005
LocalForward 11006 n1.network2.CS4238-18-01.ncl.sg:11006
LocalForward 11007 n1.network2.CS4238-18-01.ncl.sg:11007
@jaysoncena
jaysoncena / hw4.py
Created November 24, 2018 12:50
CS4238 HW4
import datetime
import requests
cookies = {
'phpbb2mysql_data': 'a%3A2%3A%7Bs%3A11%3A%22autologinid%22%3Bs%3A0%3A%22%22%3Bs%3A6%3A%22userid%22%3Bs%3A1%3A%222%22%3B%7D',
'phpbb2mysql_sid': '3710d7a0fb22e2763fc19ed2b2ef2842',
'phpbb2mysql_t': 'a%3A4%3A%7Bi%3A2%3Bi%3A1543061709%3Bi%3A3%3Bi%3A1543061714%3Bi%3A4%3Bi%3A1543061719%3Bi%3A5%3Bi%3A1543062076%3B%7D'
}
params = {}
@jaysoncena
jaysoncena / bytepool1.go
Created July 18, 2019 02:10
`[]byte` pool using sync.Pool
package main
import (
"sync"
"net"
)
const MaxPacketSize = 4096
var bufPool = sync.Pool {
@jaysoncena
jaysoncena / bytepool_http2.go
Created July 18, 2019 02:12
`[]byte` pool using sync.Pool with different sizes
// From https://github.com/golang/go/blob/7e394a2/src/net/http/h2_bundle.go#L998-L1043
// Buffer chunks are allocated from a pool to reduce pressure on GC.
// The maximum wasted space per dataBuffer is 2x the largest size class,
// which happens when the dataBuffer has multiple chunks and there is
// one unread byte in both the first and last chunks. We use a few size
// classes to minimize overheads for servers that typically receive very
// small request bodies.
//
// TODO: Benchmark to determine if the pools are necessary. The GC may have
#include <stdio.h>
#include <stdlib.h>
void trickme(FILE *f)
{
char buf[24];
long i, fsize, read_size;
puts("How many bytes do you want to read? (max: 24)");
scanf("%ld", &i);
@jaysoncena
jaysoncena / fixed_numpy_array.py
Created November 9, 2019 06:46
Resize numpy array to a fixed size and pad with np.nan
def load_npy_files(path, range_val=(), row_col=(0,0)):
total_rows = 0
total_cols = 0
max_cols = 0
max_rows = 0
row_size_list = []
dataset_list = []