Posts

Showing posts from September, 2018

[Prisma] Notes on Prisma + Docker

This is a documentation as a result of trying out https://github.com/prisma/prisma#quickstart Some notes on Prisma commands: docker-compose up -d : 'compose' starts the YAML file that configures your application's services. Can be used to run multiple containers at once. (YAML file: docker-compose.yml) docker-compose down: stops containers and removes containers, networks, volumes and images created by 'up' prisma deploy : prisma playground Some notes on postgres \l : show database \dt : show tables Accessing database (created by prisma) 1. docker ps -a (to get list of docker containers history) 2. Find the container with 'IMAGE' of postgres or mysql and remember its container id. 3. docker exec -it <container id> sh (attach onto docker container) 4. psql -d postgres -U prisma -W 5. Enter pw - usually 'prisma' 6. \dt default$default.  (to see all the tables in schema default$default) 7.  select * from default$default.

[Encoding] Binary to Text Encoding

Binary, ASCII and Text Data Binary data is a sequence of 8 bit bytes, where each byte can have a value between 0x00 and 0xFF. In general, we can’t assume much about this data, except that any byte could potentially have any value. ASCII data represent text as a sequence of bytes. In the ASCII system, byte values in the range 0x00 and 0x7F are used to represent English language letters (upper and lower case), numerals, punctuation symbols and various ‘control code’. Byte values above 0x80 have no well defined meaning in ASCII. Since ASCII data is not expected to contain byte values of 0x80 or greater, it is often called 7-bit data. Printable characters in ASCII are values in range 0x21 to 0x7E, which includes upper and lower case characters, numerals and all standard punctuations.   Text data is ASCII data which only contains printable and whitespace characters. Binary-to-text encoding is encoding of data in plain text. More precisely, it is an encoding of

[Encoding] Binary Mode

Have you ever tried writing a software to read a zip file and send it over the server, only for the server to receive something different? If you do, one of the possible reasons is you are not reading your zip file correctly. A beginner mistake is to read a zip file as if you are reading a text file.  Remember, text, in the computer world, are bytes interpreted by a specific type of encoding . If you program your software to read your zip file as if it is reading a text file, you might end up using the wrong encoding, and thus, be unable to interpret your zip file later on. Personal Experience I got this problem when I was trying to add a feature where you download zip from the server via my web site. My server and webapp were coded in Ruby, so I'm going to use Ruby syntax. At first, I used File.read(...) to read my zip file. Then I do an encode64 because my webapp crashes when it sees unreadable characters. In my webapp, I then decode64 (since I encode64-ed it in the se

[Encoding] Character Encoding

Character encoding If you ever thought that: plain text = ascii = characters are 8 bits  You are SUPER wrong! History of Character Encoding ASCII (0-127) Back when unix was invented, the only characters that mattered were unaccented English letters, represented with a code for them called ASCII. ASCII was able to represent every character using a number between 32 and 127. Eg. Space was 32, and the letter "A" was 65. This could all be stored in 7 bits. Most computers back then were using 8-bit bytes, so not only could you store every possible ASCII character, but you still have one bit to spare. Codes below 32 were called unprintable. They were used for control characters, like 7 which made your computer beep and 12 caused the current page of the paper to go flying out of the printer. Everything was good - assuming you were an English speaker. ASCII (128-255) Because bytes have room for up to 8 bits, lots of people started thinking how they can use cod

[Network] Will we run out of IP addresses?

So before we answer the question - Will we run out of IP addresses? - I will first explain the two main types of IPs out there; IPv4 and IPv6. But if you can't wait, the short answer is no; but the long answer is depends on how you define IP. What are Internet Protocols (IP) addresses? In short, they are an unique number that gets linked to all online activity you do; like a return address on a letter you'd send out. an IP address to your internet device. Your internet activity goes through them, and they route it back to you; using your IP address. IP addresses are assigned to your computer by Internet Service Provider (ISP; like AT&T, Comcast.etc). It's their role to assign Note that IP addresses are not permanent. Even if you are at home, simply turning your modem or router on and off, or contacting your ISP will change your IP. IPv4 and IPv6 The Internet Protocol version 4 (IPv4) is a protocol for use on packet-switched Link Layer networks (e.g. Ethern

[Terminal] Finding port availability and killing process using it

Image
To find out if there are any processes using a particular port, you should run the following command line: lsof -n -i4TCP:<PORT NUMBER> which will give you the following: Then, enter the following cl to kill the process: kill -9 <PID> More Info lsof: means list open files lists file information about files opened by particular process(es)ers to host names for network files.  -n option makes the command faster by preventing it from doing an IP to hostname conversion. -i[internet address] option selects the listing of files whose internet address matches the internet address.  Internet address format:  [4 or 6][protocol][@hostname | hostaddr][:service | port] The 4 or 6 refers to IPv4 and IPv6 Resources: https://stackoverflow.com/questions/3855127/find-and-kill-process-locking-port-3000-on-mac

[Java] Servlets

A servlet is a class which responds to a particular type of network request (most commonly an HTTP request). Servlets are usually used to implement web applications. Servlets run in a servlet container, which handles the network side (eg. parsing HTTP request, connection handling.etc). One of the best-known source servlet containers is Tomcat. Flow of Request Client sends HTTP request to Web Server Web Server forwards HTTP request to Web Container Web Container converts request into valid request object (because servlet cannot understand HTTP; only understands objects) Web container spins a thread for each request. All the business logic goes inside doGet() and doPost() methods inside the servlets. Servlet builds a Java response object and sends it to the container. It converts that to HTTP response again and send it to the client.