I struggled to wrap my head around these two new operators, the && and the ||.
So I decided to write a post about them to explain them to myself.
var || 'hi' will return 'hi' when false
var && 'hi' will return 'hi' when true
So:
var || 'hi' means:
return 'hi' if var is false
--or--
var ? var : 'hi'
and:
var && 'hi' means:
return 'hi' when var is true
--or--
var ? 'hi' : var
Tuesday, 11 April 2017
Wednesday, 4 January 2017
Flashing a bricked SP Racing F3 Flight Controller
I've been struggling for two days with this and finally found the solution. Scroll down for that.
Background:
So my UART2 plug broke off after a bad crash causing my quad to drop out of the sky on the next flight. Once I found the broken port, I thought that I could simply plug it into a new one, so I did.
Once connected I had problems getting the RX to be recognised, so I thought that the setting must be in Cleanflight. I went to the ports tab and changed some settings and boom, lost connection after saving. Since then I couldn't reconnect.
I tried the following, to no avail:
- I tried the Zadig driver fixer when the ports weren't available,
- I tried the ImpulseRC Driver fixer
- I tried the STM flash loader demonstrator - this worked after a few tries, but then I stopped being able to connect to the FC again.
- I tried various SP Racing firmwares, thinking that perhaps I didn't have the same model
Anyway, finally I find a reddit post and I actually read the whole thread for once, and way at the bottom I get the answer.
Solution:
- I went to 'Add or Remove Programs or Features' and removed the CP210 drivers(look for software by Silicon Laboratories Inc.)
- Then I removed the STM3 drivers, just search for STM in the list.
- Finally I installed the CP210 drivers again, and ignored the STM3 drivers.(these drivers can be downloaded from the links on the Cleanflight landing screen.
- I opened Cleanflight and in the Firmware Flasher I selected my FC model and firmware version. I also checked:
"No reboot sequence"
"Flash on connect"
"Full chip erase"
and "Manual baud rate" and I set it to 256000 - I then clicked on "Load Firmware(Online) and waited for it to be loaded
- I shorted out the two boot pins(google to find yours) on my FC and then plugged in the USB.
BOOOM! instant flashing, no more USB errrors or bootloader errors like before!
I hope this helps you as it helped me
I hope this helps you as it helped me
JavaScript replace() method's deviousness!
There is a trick to this method, if you do:
var test = 'old old old';
test = test.replace('old','new');
console.log(test);
The output would not be as expected, you would get:
'new old old'
However, if you remove the quotes and add regex tags:
test = test.replace(/old/g,'new');
You will get every instance replaced in your string.
My pleasure!
var test = 'old old old';
test = test.replace('old','new');
console.log(test);
The output would not be as expected, you would get:
'new old old'
However, if you remove the quotes and add regex tags:
test = test.replace(/old/g,'new');
You will get every instance replaced in your string.
My pleasure!
Tuesday, 22 November 2016
Setting up easy SSH connection.
We'll need to generate a key in order to access our server easily from our home machine.
To generate a key, enter the following on your client PC(probably the PC you're working on)
ssh-keygen -t rsa
You will be prompted to enter a filename of the key generated. It's not necessary, but should you decide to enter one, make sure to enter the full path of where you would like the file to be saved.
Enter file in which to save the key (/home/demo/.ssh/id_rsa):
Next, you will be asked if you want to enter a passphrase. This is great if you'd like to add some security client-side so that anyone using your machine can't just gain access to the remote server.
You will be prompted twice for the password:
Enter passphrase (empty for no passphrase):
This is what you'll see after completing the ssh-keygen operation:
Our next step is to copy the key to the remote server. Lucky for us there's an easy command to achieve this:
ssh-copy-id root@789.123.45.67
Enter the remote username and the remote IP as above.
You will be prompted for the password of the remote server. Enter it and the key will be copied over.
Once done, test if it all worked out by doing an SSH to the server and seeing if it logs you in automatically:
ssh root@89.123.45.67
Well done, so far so good. Now let's make things a little easier by adding an alias to the ssh command, that way we won't have to remember every server's IP address.
sudo vim ~/.bashrc
Ofcourse this assumes you use bash, I use zsh for example and had to edit my ~/.zsh file instead.
Once your file is open, enter the following on a new line:
alias myaliascommand="ssh root@89.123.45.67"
Press escape and run: :wq to save the file and exit.
Your bash aliases will be available on the next new terminal you open, but if you're like me, you don't like closing and opening terminals for no reason, simply run:
$ source ~/.bashrc
..and this will refresh the .bashrc resource in your bash.
Now test by typing myaliascommand and see how it connects to the server with a single command!
I hope this saves you tons of time, bye now!
To generate a key, enter the following on your client PC(probably the PC you're working on)
ssh-keygen -t rsa
You will be prompted to enter a filename of the key generated. It's not necessary, but should you decide to enter one, make sure to enter the full path of where you would like the file to be saved.
Enter file in which to save the key (/home/demo/.ssh/id_rsa):
Next, you will be asked if you want to enter a passphrase. This is great if you'd like to add some security client-side so that anyone using your machine can't just gain access to the remote server.
You will be prompted twice for the password:
Enter passphrase (empty for no passphrase):
This is what you'll see after completing the ssh-keygen operation:
ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/demo/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/demo/.ssh/id_rsa. Your public key has been saved in /home/demo/.ssh/id_rsa.pub. The key fingerprint is: 4a:dd:0a:c6:35:4e:3f:ed:27:38:8c:74:44:4d:93:67 demo@a The key's randomart image is: +--[ RSA 2048]----+ | .oo. | | . o.E | | + . o | | . = = . | | = S = . | | o + = + | | . o + o . | | . o | | | +-----------------+
Our next step is to copy the key to the remote server. Lucky for us there's an easy command to achieve this:
ssh-copy-id root@789.123.45.67
Enter the remote username and the remote IP as above.
You will be prompted for the password of the remote server. Enter it and the key will be copied over.
Once done, test if it all worked out by doing an SSH to the server and seeing if it logs you in automatically:
ssh root@89.123.45.67
Well done, so far so good. Now let's make things a little easier by adding an alias to the ssh command, that way we won't have to remember every server's IP address.
sudo vim ~/.bashrc
Ofcourse this assumes you use bash, I use zsh for example and had to edit my ~/.zsh file instead.
Once your file is open, enter the following on a new line:
alias myaliascommand="ssh root@89.123.45.67"
Press escape and run: :wq to save the file and exit.
Your bash aliases will be available on the next new terminal you open, but if you're like me, you don't like closing and opening terminals for no reason, simply run:
$ source ~/.bashrc
..and this will refresh the .bashrc resource in your bash.
Now test by typing myaliascommand and see how it connects to the server with a single command!
I hope this saves you tons of time, bye now!
Monday, 21 November 2016
Some trickyness when setting up git
Tell git to remember your passwords forever with:
git config --global credential.helper store
Set your upstream forever with:
git config --global push.default current
Make git remove the annoying .orig files after merging:
git config --global mergetool.keepBackup false
Make git forget about that file:
git config --global credential.helper store
Set your upstream forever with:
git config --global push.default current
Make git remove the annoying .orig files after merging:
git config --global mergetool.keepBackup false
Bonus commands:
Make git forget about a file that's already tracked:You've been tracking a file and realised it's not a good idea, so you added the file to the .gitignore, but git still wants to commit the changes you made to it, what do you do?Make git forget about that file:
git rm --cachedWednesday, 7 September 2016
Wordpress and AJAX headaches for days
I just spent over 3 hours wondering why my ajax function only returns 0, yet when I use the exact same function in PHP elsewhere, it returns the correct value.
Turns out, all ajax functions must exit, otherwise the wordpress engine will take over and do other evil things, ending up in world domination and the destruction of mankind!
add_action( 'wp_ajax_my_function', 'my_function' );
Turns out, all ajax functions must exit, otherwise the wordpress engine will take over and do other evil things, ending up in world domination and the destruction of mankind!
So remember, echo and exit, or your life will be hell!
add_action( 'wp_ajax_my_function', 'my_function' );
function my_function() {
echo 'response';
exit;
}
Gulp Debugging
I recently ran into a problem where Gulp wouldn't give me the line where a parse error had occurred.
The problem was in the uglify dependency.
To solve it, after much googling, I did the following:
Add this to the beginning of the gulpfile.js:
process.on('uncaughtException', function(error) {
...and then in the guilty task, make sure the uglify function is called first(so that you don't lose line numbers or other data with minify):
var jsTasks = function(filename) {
The problem was in the uglify dependency.
To solve it, after much googling, I did the following:
Add this to the beginning of the gulpfile.js:
process.on('uncaughtException', function(error) {
console.log(error);
process.exit(1)
});
...and then in the guilty task, make sure the uglify function is called first(so that you don't lose line numbers or other data with minify):
var jsTasks = function(filename) {
return lazypipe()
.pipe(uglify, { // THIS HAS BEEN MOVED UP compress: { 'drop_debugger': enabled.stripJSDebug } }) .pipe(function() {
return gulpif(enabled.maps, sourcemaps.init());
})
.pipe(concat, filename)
.pipe(function() {
return gulpif(enabled.rev, rev());
})
.pipe(function() {
return gulpif(enabled.maps, sourcemaps.write('.', {
sourceRoot: 'assets/scripts/'
}));
})();
};
Subscribe to:
Posts (Atom)
-
I've been struggling for two days with this and finally found the solution. Scroll down for that. Background : So my UART2 plug b...
-
I have learnt a few things in the last few months of flying and I would like to share it with the world. There's no use struggling when ...
-
Just an update: Here's my attempt(still needs a lot of texturing work) at remaking Alpha crater. Hardwar has a game mode where you ...