Categories
Uncategorized

How to update your FosJsRoutingBundle routes file

When you add a new route to one of your Symfony API routes aka your controllers, you will need to recreate the JSON routing file that FosJsRoutingBundle uses.

To do that you use this simple command.

php bin/console fos:js-routing:dump --format=json --target=public/js/fos_js_routes.json

This command will rewrite your existing routes JSON file located in the public folder of your project.

Then to make sure your routes are working you display them with this command.

php bin/console fos:js-routing:debug

This will output your currently available routes created with the line above.
To learn more about the command read this short article. How to view Symfony 5+ FosJsRoutingBundle routes

To learn how to get the Javascript routes in your javascript code in the first place with FosJsRoutingBundle read this book I wrote on the subject. LOL How to get URL Routes in your Javascript in Symfony 5+

Categories
Uncategorized

How to fix Symfony Compile Error: Cannot use Repository as Repository because the name is already in use

So you got this error? WTF does it even mean?

baby what does that even mean meme
What does this error mean?

Well my actual error was this.
Compile Error: Cannot use App\Repository\PageUrlsRepository as PageUrlsRepository because the name is already in use

I oopsied

You can see here what I did is accidentally add a second use statement. I remove that and BOOM all back to normal.

Categories
Uncategorized

How to configure a fake domain name on your localhost on linux aka virtualhosts

Often when testing a web project locally you will use something like http://localhost:9000. Unless you are using Docker and dockerizing your app. What if you want to run multiple apps or multiple versions of one app at the same time and instead of going to localhost:9000, localhost:9001 etc. etc. you want to go to https://yourappname and https://yourapp-name2 …

Well on linux you edit the Hosts file and create a loopback to localhost 127.0.0.1 or whatever IP you want. I mostly leave it with the localhost loopback though to prevent myself from blocking access to other websites on accident.

Here is an example of my hosts file, you can see I have made quite a few changes. This file is usually located at /etc/hosts there is no document type just “hosts” is the name.

127.0.0.1 localhost
127.0.1.1 sogi-test
127.0.0.1 sogizmo
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Now this way I can type http://sogizmo and my app opens on localhost. I can open another tab and type http://sogi-test. This is also handy for testing that your app works correctly with SSL/https. I’ll cover how to do that in another article later.

Note if you add a .com to the end of your app names you block your access to the real app from your device only. That is, your PC uses the hosts file to lookup hosts before hitting your router which hits your ISP servers, which does a reverse lookup. If you have example.com in your hosts file and try to access that from your computer that you made changes to the hosts file on, it will take you to your local copy not the .com website so remember not to add the .com

I still find the old fashioned way easier for now. Plus I haven’t fully embraced Docker other than running things my app needs without installing them. I am slowly moving more towards dockerizing everything.

There is still more to do to get the app to work correctly on your system though. You will also need to configure your local server to serve pages from your apps local root directory.

I use Nginx so this is as easy as a few lines of code and a few minor changes. The files are located in /etc/nginx/sites-available. I wont cover the configuration because it is different for each app, however the location is always the same.  Here is a link about configuring Nginx. Here is the official documentation for Nginx.

Basically inside the Nginx configuration you want to set the name of the server to the same as the name you listed in the “hosts”file for me it is sogizmo.

Like so :

server_name sogizmo;

Then you need to tell Nginx where your server root is on my system for my app it is

root /var/www/sogizmo/public;

So basically that is it. You add your desired site name in the hosts file with an ip such as 127.0.0.1. Then you create your Nginx or Apache configuration and set your server to match the name you added in the hosts file. Then you set the root directory for your app. There are also other things you will need to set in the configuration based on the tech stack your app uses.

Categories
Uncategorized Web Development

Why most current social platforms suck

One major problem with most current social platforms is they randomly ban people for things that are not offensive.

You can’t even make a joke on these platforms. They ban people for making jokes like the following.

Social censorship at it’s finest

Anyone with an IQ over 75 can clearly see I am making a joke here about how much Javascript sucks. In no way am I telling anyone to harm themselves or saying I want to harm myself.

What kind of petty broken censorship system is this?  Is this AI making these judgements? If so it sucks.
Did  some amateur that just started to learn to code, who is totally in love with Javascript reported this? If so grow up and learn some other languages and you will realize Javascript sucks.

I use Javascript all day every day for user interface creation, which is probably why I hate it. It just swallows things that should be an error or warning, making debugging harder. The 100% lack of a type system makes it really suck BAD BAD BAD. You never know what is going to be passed to functions. This. Don’t get me started on this in Javascript.
Javascript was one of the first languages I learned 15 years ago now. I have plenty experience with Javascript. I also have used Golang, PHP, Perl, Java, Scala, Actionscript, VB.NET, Sketchs, BASH and more. I speak out of experience not failure.

And if you are a Javascript fanboy and don’t know why it sucks… read this article. Javascript gives you secret hidden bugs and errors.

So much suck in 1 language

 

Categories
Uncategorized

Symfony events resources, links and videos

To see a list of all events use this command

 php bin/console debug:event-dispatcher

Built-in Symfony Events – this covers some of how events work in Symfony and the basic default events that fire with every request.

The HTTP kernel component – This gets to the core of Symfony and it’s event system. The kernel is driven by events. This also covers the basic flow of events that symfony follows when a request enters the system.

Events and event listeners – More information about symfony events.

The EventDispacher component – This is more about the symfony system events.

An example of how to use the EventDispacher component

Videos

This video covers how to create a custom event subscriber

Categories
Uncategorized

Bash how write large amounts of text to a file

I searched and tried for days to find the answer to this. All I wanted to do was be able to basically create a file and write text to it exactly as I had entered it in a shell script. Every suggestion on the internet was fubar.

Note : to run these commands, put them in a folder like test.sh and use chmod 755 test.sh to make it executable then type bash test.sh or sh test.sh or /.test.sh

I wanted to put something like this in a file from within a shell script.



Line one text
   Line two text
   line three text
   lets talk about some text

I tried everything. I googled for days and I finally found this article  where someone had basically the same need as me. Basically the syntax to put a bunch of text into a file from shell script is this.


#!/bin/bash
testFile=/home/akashicseer/tests/test-file.txt
if [ ! -e $testFile ]; then
    touch $testFile
fi
outside_var="Some text from outside hell"

cat <<TEST  >> $testFile
Line one text
   Line two text
   line three text
NEWVAR = values
lets talk about some $NEWVAR
or not
but look at some outside text $outside_var
TEST

This uses <<HEREDOC syntax but it also redirects the input with >>. This is the oddest syntax I have ever seen so I can’t explain why it works. I would expect the redirect to be at the end of the closing TEST, but that doesn’t work. Bash heredocs are the weirdest thing other than if statements I’ve come across. Learning bash has been like traveling back in time to the 70’s or 80’s the syntax is beyond odd.

Also you will notice I tried defining a variable in the heredoc. That doesn’t work. You can copy and paste the code above and see what I mean. You don’t get errors but the variable doesn’t expand. I don’t know if it is supposed to or not. Here is a link to some info about heredoc. However what you can do is define variables outside the heredoc and use them within, see the $outside_var.

If you read the “info about heredoc” link above( in links below too) it shows this alternate syntax which works too, and makes more sense. I honestly don’t know how or why  the above ugly mess works.


#!/bin/bash
testFile=/home/akashicseer/tests/test-file.txt
if [ ! -e $testFile ]; then
    touch $testFile
fi
outside_var="Some text from outside hell"

cat > $testFile <<TEST
Line one text
   Line two text
   line three text

   but look at some outside text $outside_var
TEST

This looks a little better to me than the other version. So there you have it that is how you write lots of text to a file.  I had to search for days to figure this out so I hope this saves at least one person some time.

Version 1 heredoc syntax
Version 2 heredoc syntax

Categories
Software Development Uncategorized

Linux xclip command makes command line life easier

I discovered a new tool today while adding my ssh keys to Github, something called xclip.

The xclip command makes it easy to capture output to the clipboard so you can paste it to another location like into a browser or word file etc.

The github docs above have you use it to copy your RSA key and save it for pushing your repository so you don’t have to supply a user name and password.

xclip -selection clipboard < ~/.ssh/id_ed25519.pub

The above tells xclip to put the contents of id_ed25519.pub into the clipboard. You can then use ctrl + v to paste it anywhere you need it.

Here is more info and examples on how to use xclip

Link to some man page  type info about the options it accepts as arguments.

Another link to similar info about xclip it’s options etc.

Categories
Uncategorized

C programming language resources and links

C Syntax Rules – Learn the ABCs of Programming in C Language

Above is a great link to get started with C programming languge

 

Categories
Uncategorized

Undocumented parts and pieces of Scala magic

I constantly run into things that are not in the documentation of Scala or if they are they are hidden. This kind of stuff only increases the learning curve of Scala. Any increase in the learning curve decreases acceptance rates.

Self typing. The docs only show one single way, but low and behold there are more ways. Imagine that. Disambiguating ‘this’ in Scala, or what does ‘self =>’ mean?

 

Categories
Uncategorized

random interesting science articles

Wonder Material Mimics Desert Beetles and Cacti To Suck Water Out of Thin Air

Quantum researchers create an error correcting cat.

How earthquake resistant buildings work. – Cool article that talks about pyramid structures.