Posts by Ramil (148)

today I made love to my woman.

Not because I wanted to right then, but because I knew I'd want to once we started. And that the walk on the beach we took afterward would be more romantic. The cocktail I made at 5:45 would taste better. The shrimp I seasoned would have more savor. The All-Star game we watched at 7 would be more exciting. The music we danced to till midnight would have more rhythm. And the conversation about life we had together sitting across the kitchen table from each other until 3 in the morning would be more inspiring . . . And it was. - Greenlights, Matthew McConaughey

Lex Fridman's posting

I wrote a quite long summary/description of what I did with the SmartBoard project, so makes sense to post it here as well! Project SmartBoard I've been longboarding for a while, and I really enjoyed Raspberry Pi (Zero W specifically, what a beauty) so to make my board much cooler I wanted it to have a perimeter of LEDs that would automatically respond to various actions (turning left/right, accelerating, etc.) with awesome light patterns. The following aren't necessarily in order: Part 1: Get an idea of the functionality I would like it to have. This resulted into: - Brain (Raspberry Pi) - Senses (Some sort of sensor to track movement) - Controller (Infrared controller I found in an old Arduino set) - Output (LED Strip) Part 2: Getting LED Strip. Quiet straightforward research, settled on WS2812B model since it was relatively cheap ($20-25), was waterproof, and had some documentation for RaspPi integration. Part 3: IMU sensor. To track movement I wasn't quite sure what I needed/what existed on the market. TLDR: I ended up purchasing 3 different sensors: - MPU6050 - cheap, only had 6 Degrees of Freedom (DOF) which I later found to be insufficient - MPU9250 - mid expensive, had 9 DOF (Gyro, Accelerometer, +Magnetometer) which in theory would have been very useful, as allows to track Earth's magnetic field as well, but turned out to be defective and ran out of stock - MPU9250+Built-In Kaplan filter - quite expensive for me at the time ($45), but it had a built in Kaplan filter, which I knew I needed from my experiments with MPU6050 (essentially data was very noisy - turns out riding a longboard isn't as smooth as it feels). Part 4: IR remote. I eventually realized that sometimes I want to trigger certain patterns manually, so I've added a remote controller I had lying around from some Arduino set (which was much more difficult than it sounds). Part 5: Raspberry Pi Brain + Circuit. As I'm assembling various components, I'm concurrently writing Python code to test circuits / sensors / led strip response. Since there is a lot to cover, I'll list the problems I overcame to make everything work: - Setting up RaspPi headless (establishing SSH and utilized the wifi capability of Zero W) - Integrating a power source as not to burn LED strip / Rasp Pi since both required very different voltages/currents - Attaching all the inputs/outputs to raspberry pi pins (+ software configurations) - Creating a case sturdy enough to not fall apart, hold all the circuit pieces and be developer-friendly (i.e. could assemble/disassemble easily) - Literally reading Chinese forums to figure out how to utilize the infrared controller - Writing code to interpret the movement signal (knowing if the board is turning is harder than it sounds) - Code to produce awesome led patterns (arguably the most important part) I'm sure there is something I'm missing, but since it's getting too long, I'll stop here, and hopefully, if you are interested, we could talk more about my journey. Again, all of it is documented in my github / blog / projects tab / silly youtube video.

Python bug/feature which costed me an hour of my life

What's wrong with the code below?

>>> def func(n=5, arr=[]):
...     arr.extend(["hi"] * n)
...     return arr
This function :
  1. Takes in integer value, n and an array, arr
  2. Appends n "hi"s to the array
  3. returns the resulted array
If we call this function, then we get the expected output
>>> func(3)
['hi', 'hi', 'hi']
But... what if we call it again?
>>> func(3)
['hi', 'hi', 'hi', 'hi', 'hi', 'hi']
Wait, what? n is 3, so why do we get 6 "hi"-s ?
>>> func(5)
['hi', 'hi', 'hi', 'hi', 'hi', 'hi', 'hi', 'hi', 'hi', 'hi', 'hi']
huh? 13 times? Why does it append to the previous result?? Well, after playing with various iterations, I came to realize that the default value inside the function definition is created only once. I.e. inside the def func(n=5, arr=[]): python remembers to use created empty array as a default value. But actually, it only remembers the reference to the array, not the array itself. So when it's modified, still in the next call it still refers to the same object, it uses the modified array as a default. Anyway, that's kinda insane and cool, but I've read on StackOverflow that it has some good reasons. I'll post a link later, gotta take a shower.

1800+

Finally :') My chess rating has gotten above the magic number

FastAPI

Purchases a FastAPI Bundle. Really excited about this, since my interaction with it was so pleasant so far.

1 ... 6 7 8 ... 30