Skip to content

Instantly share code, notes, and snippets.

View TheLittleNaruto's full-sized avatar
🎯
Focusing

TheLittleNaruto TheLittleNaruto

🎯
Focusing
View GitHub Profile
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
@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)
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"])
dispatch = {
'foo': int,
'bar': json.loads,
'foobar': something,
}
def identity(x): return x
cleaned = {}
for key in raw:
@TheLittleNaruto
TheLittleNaruto / deletion_of_keys_in_dict_correctly.py
Created February 5, 2020 07:00
Comprehension in python dict or list
list_ = list(range(6))
for idx, val in enumerate(list_):
print(idx, val)
if idx%2: #we think we wrote code that deletes every item at odd indices
del list_[idx]
print(list_)
#compare to
@TheLittleNaruto
TheLittleNaruto / MainActivity.kt
Created May 13, 2020 17:19
Example on Logging for Medium article blog on Logging and debugging
class MainActivity : AppCompatActivity() {
companion object {
val TAG = MainActivity::class.java.simpleName
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "$TAG=> onCreate()")
}
$ adb tcpip 5555
$ adb connect <Mobile Device IP Address>:5555
# Example:
$ adb connect 192.168.1.5:5555
$adb devices
List of devices attached
192.168.1.5:5555 device
$ adb logcat -s *:V #Verbose filter
$ adb logcat -s *:D #Debug filter
$ adb logcat -s *:I #Info filter
$ adb logcat -s *:W #Warning filter
$ adb logcat -s *:E #Error filter
$ adb shell setprop log.tag.MainActivity DEBUG
$ adb logcat -s MainActivity:V
05–13 22:54:51.539 2885 11072 I MainActivity: MainActivity=> onCreate()