Skip to content

Instantly share code, notes, and snippets.

View TheLittleNaruto's full-sized avatar
🎯
Focusing

TheLittleNaruto TheLittleNaruto

🎯
Focusing
View GitHub Profile
dispatch = {
'foo': int,
'bar': json.loads,
'foobar': something,
}
def identity(x): return x
cleaned = {}
for key in raw:
import user_from_dict, user_to_dict
data = {"name": "Uzumaki Naruto", "village": "Leaf Village"}
usr = user_from_dict(data)
print(usr.name)
usr_dict = user_to_dict(usr)
print(usr_dict["village"])
@TheLittleNaruto
TheLittleNaruto / PojoToDict.py
Created October 15, 2019 13:02
helper methods to serialize and deserialize objects
def user_from_dict(s: Dict[str, Any]) -> User:
return User(**s)
def user_to_dict(x: User) -> Dict[str, Any]:
return vars(x)
Traceback (most recent call last):
File "TheLittleNaruto/test.py", line 8, in <module>
print(concatenate(a="Real", b="Python", c="Is", d="Great", e="!"))
TypeError: concatenate() got an unexpected keyword argument 'c'
Process finished with exit code 1
# concatenate.py
def concatenate(a: str, b: str):
result = ""
result += a
result += b
return result
print(concatenate(a="Real", b="Python", c="Is", d="Great", e="!"))
@TheLittleNaruto
TheLittleNaruto / kwargs_demo.py
Created October 15, 2019 12:52
Understanding kwargs in Python
# taken from https://realpython.com/python-kwargs-and-args/
# concatenate.py
def concatenate(**kwargs):
result = ""
# Iterating over the Python kwargs dictionary
for arg in kwargs.values():
result += arg
return result
print(concatenate(a="Real", b="Python", c="Is", d="Great", e="!"))
@TheLittleNaruto
TheLittleNaruto / Makefile
Created October 3, 2019 12:38
Make file to compile and build the driver module.
obj-m:=hello.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean
@TheLittleNaruto
TheLittleNaruto / hello.c
Created October 3, 2019 10:43
Hello Driver
#include<linux/module.h>
#include<linux/init.h>
#include<linux/kernel.h>
static int hello_init(void){
printk(KERN_ALERT "Hello TheLittleNaruto; it's your first driver which d oes no shit :/\n");
return 0;
}
static void hello_exit(void){
@TheLittleNaruto
TheLittleNaruto / CustomToast.kt
Last active July 21, 2020 09:26
Custom Toast Helper
/*
* Copyright (C) 2019 @author TheLittleNaruto
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
<option name="taskNames">
<list>
<option value="assembleRelease" />
<option value="myCustomTask1" />
<option value="myCustomTask2" />
</list>
</option>