Skip to content

Instantly share code, notes, and snippets.

View danilomo's full-sized avatar

Danilo Oliveira danilomo

View GitHub Profile
-- usage: tshark -r something.pcapng -q -X lua_script:tap.lua
local teid = Field.new("gtp.teid")
local teid_cp = Field.new("gtp.teid_cp")
local gtp_msg = Field.new("gtp.message")
local user_ipv4 = Field.new("gtp.user_ipv4")
local rat_type = Field.new("gtp.ext_rat_type")
local time = Field.new("frame.time_epoch")
local frame_number = Field.new("frame.number")
!
! Swap Caps_Lock and Control_L
!
remove Lock = Caps_Lock
remove Control = Control_L
keysym Control_L = Caps_Lock
keysym Caps_Lock = Control_L
add Lock = Caps_Lock
add Control = Control_L
instruction_set = {}
import string
def command( func ):
def exec_(regbank, op, val = None ):
if(val):
pc = func(regbank, op, val)
else:
pc = func(regbank, op)
@danilomo
danilomo / ZipWithIndex.java
Last active November 6, 2018 13:52
"Zip with index" in Java 8 stream API
import java.util.Iterator;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import javafx.util.Pair;
public class ZipWithIndex {
public static void main(String[] args) {
Stream<String> s = Stream.of("One", "Two", "Three", "Four", "Five");
@danilomo
danilomo / Decorator.java
Created June 8, 2018 11:17
Example of decorator pattern
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.teste;
import java.util.HashMap;
import java.util.Map;
@danilomo
danilomo / chain.py
Created June 7, 2018 11:09
Emulating bash's chain of commands ( && operator )
class LinkedList:
def __init__(self, head, tail):
self.head = head
self.tail = tail
def reverse(self):
l = self
newl = None
while l:
newl = cons(l.head, newl)
@danilomo
danilomo / VisitorAlternative.java
Created June 6, 2018 07:01
Visitor pattern revisited
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package visitorchallenge;
import ast.Exp;
import ast.MulExp;
import ast.NegExp;
@danilomo
danilomo / VisitorOld.java
Created June 6, 2018 07:00
Visitor pattern example
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package visitorchallenge;
import ast.Exp;
import ast.MulExp;
import ast.NegExp;
@danilomo
danilomo / pomodoro.sh
Created May 8, 2018 15:44
pomodoro timer
#!/bin/bash
function check-command {
type $1 > /dev/null 2>/dev/null
if [ $? -ne 0 ]
then
(>&2 echo "Command $1 expected, but not found.")
(>&2 echo "Please install dependencies: sudo apt-get install sqlite3 jq")
exit 1
@danilomo
danilomo / stack.fs
Created March 26, 2018 15:30
Reverse last n items on the stack
: create-stack
dup
1 + cells allocate throw dup 0 swap !
over over swap cells erase
swap drop
;
: write-on-top ( address n -- address ) swap dup dup @ 1 + cells + rot swap ! ;
: move-cursor ( address n -- address ) over dup @ rot + swap ! ;