Month: December 2015

Clean up your header navigation in Ruby on Rails

Use an array. Like the below.

&lt;% links_array = [{title: "test", link_text: "Test", link: linky}, {title: "test2", link_text: "Test2", link: linky}] %&gt;<br>

Then to show the links place the below in the “ul” tags.

&lt;% links_array.each do | l | %&gt;<br>&lt;li&lt;%= sanitize is_active(yield(:title), l[:title]) %&gt;&gt;&lt;%= link_to l[:link_text],   l[:link] %&gt;<br>&lt;% end %&gt;<br>

You can make more then one array for different sections. Or you could store it in the database.

How to make money from your site

Depending on what you post on your site ads might be useless. If there’s anything about tech, then you know your visitors will be using ad blockers.

So get rid of your ads, as that won’t provide an income.

You’ll need to force your visitors to pay to read anything on your site. That can easily be done with PayPal. You can manually make them an account, or have it automated. If they dispute the charge, you can refund them, and delete their account.

You could block those using ad blockers, but you might as well block everyone if you do that. As they can use a proxy, so you’ll end up with a huge block list.

According to Awstats, this site has had 49 visits, it went down after switching to Ruby on Rails. According to Google AdSense, the ads have been viewed 18 times. As you can see almost all visitors block ads. Either they are all bots, or people that like blocking ads.

How do sites detect if you are using an ad blocker? By JavaScript? If so, all you have to do is disable JavaScript. But you can make your site not function without JavaScript. If you plan on blocking ad block users, redirect them to a porn site. I’d recommend ashemaletube, I think that’s what it’s called.

You’d have better luck finding a sugar mamma and/or sugar daddy then making money on your site.

How to get children to shut up

Yell at them. That’s what my mom did. My sister’s son was silent after she yelled at him. He’s six years old if I remember correctly, might not work on babies, three and under.

I don’t think I’ll yell at them, that’ll result in me getting yelled at, and not being allowed around them anymore. I don’t mind getting yelled at though, then we can get in a fight in front of the kids. Sounds like fun.

Fix your HTTPS warning about the Favicon

<br>  <link rel="icon" <br>      type="image/png" <br>      href="//somewhere/myicon.png" /><br>

Add that your your head section, the file doesn’t have to exist, it’ll get rid the the error though. I don’t have a Favicon.

That might of fixed the highlighter thing not always working too. Must be a Chrome bug if the Favicon isn’t secure. Nope didn’t fix the highlighter thing. Logged out and it stopped working. Got to refresh to get it to work.

How to encode code between the code or pre tag in Ruby on Rails

The code is finally right, don’t use split, it sucks, use scan. Split might work for very simple Regexp.

			&lt;% ctags = [] %&gt;<br>			&lt;% ctags.push("code") %&gt;<br>			&lt;% ctags.push("pre") %&gt;<br>			&lt;% ctags.each do | ctag | %&gt;<br>					&lt;% codes = [] %&gt;<br>					&lt;% codes = post.content.scan(/&lt;#{ctag}[^&lt;&gt;]*&gt;(.*?)&lt;/#{ctag}&gt;/m) %&gt;<br>					&lt;% if codes %&gt;<br>						&lt;% codes.each do | code | %&gt;<br>							&lt;% code.each do | c | %&gt;<br>								&lt;% c_old = c %&gt;<br>								&lt;% c = HTMLEntities.new.encode(c) %&gt;<br>								&lt;% post.content = post.content.gsub(c_old, c) %&gt;<br>							&lt;% end %&gt;<br>						&lt;% end %&gt;<br>					&lt;% end %&gt;<br>				&lt;% end %&gt;<br>

And I forgot to edit the show file, if you go to a post directly it might not work.

The JavaScript code highlighter doesn’t appear to work, that sucks. Doesn’t support ERB.
You can add more tags with “ctags.push(“tag”)”.

Fully functional, just like a fully functional transsexual.

Note: I didn’t make that Regexp. I stole it from the internet, and slightly modified it. I might of made the ending part, can’t remember.

Update
If you use TinyMCE, you don’t need to do this. But if you have old posts, you’ll need to add “HTMLEntities.new.decode(c)” before encode. Otherwise it’ll encode the already encoded HTML. Another option is to encode all the existing posts and update them in the database. But only do the code in the pre or code tag, otherwise if the post has links, they won’t work anymore.

Update
It would be better to encode the post in the pre or code tag when you save the post. That way it doesn’t have to run all the above code every time a post is shown.

How to make a random string in Ruby on Rails

<br>('a'..'z').to_a.shuffle[0..7].join<br>

Stolen from the book I bought, somehow I remembered it.

How do you make some of them capitals? Well you could make another array with all caps, then take some from one array and the other array. Might be a better way. But that’s the easiest way.

<br>s1 = ('a'..'z').to_a.shuffle[0..3].join<br>s2 = ('A'..'Z').to_a.shuffle[0..4].join<br>a = s1.split('') + s2.split('')<br>a.shuffle[0..8].join<br>

That might work, didn’t test it though. Not on linux computer. And that isn’t very good, need some capitals in the middle. Oh do another shuffle. You might want to change how many caps are in the second string. Probably only need two.

You can see the password generator in action here. Full code below.

<br>		s1 = ('a'..'z').to_a.shuffle[0..9].join<br>		s2 = ('A'..'Z').to_a.shuffle[0..2].join<br>		s3 = (0..9).to_a.shuffle[0..1].join<br>		c = ['!', '@', '#', '%', '^', '&', '*']<br>		a = s1.split('') + s2.split('') + c.shuffle[0..2] + s3.split('')<br>		p = a.shuffle[0..a.count-1].join<br>

I forgot to put numbers in it. Got to have numbers in a random password.

You can use two micro USB cables to power the Banana Pi R1?

According to this forum post, somebody uses two USB cables to boot android. I’ll plug another one in and see if sensors changes. That’s cheaper/easier then buying a battery. I’ll use the Samsung AC adapter for my tablet. It’s under 1A, so it shouldn’t fry it.

That post has pictures of AC adapters, but no links. Pretty much a useless post.

Don’t think it did anything. The voltage went up for one sensor, was 0 before. Didn’t seem to change anything else. OpenVPN is still to slow.

2 pin JST power adapter

The easiest solution is to buy a Barrel Jack to 2-pin JST and then a Wall Adapter Power Supply – 5V DC 2A (Barrel Jack) or Barrel Jack Adapter – USB to 5.5mm. The user manual for the Banana Pi R1 doesn’t say what voltage the battery connector supports, and 2A might be to much, so you could get the USB adapter, and plug it into a lower amp USB power adapter, or a USB hub.

I’m to paranoid to try it, somebody on the Banana Pi forum said it runs better with a battery. You might fry it if you use a AC adapter. I’m to lazy to be charging a battery all the time. But tinyonestore.com has a triple A battery adapter. You could put rechargable batteries in it. How long will they last?

Kind of useless for the Banana Pi R1, it has two micro USB ports. Guess if you want three power sources you can do that.

How to use Let’s Encrypt with shared hosting

You need linux of some sort on your computer, a virtual machine should work. Also you need cPanel. Don’t have hosting with any other control panel, so I don’t know how to do it. I only have one hosting account from BUYSHARED.

You’ll need letsencrypt-nosudo.

<br>mkdir ssl<br>cd ssl<br>wget https://raw.githubusercontent.com/diafygi/letsencrypt-nosudo/master/sign_csr.py<br>

Follow the instructions on GitHub.

When the Python script says to run a python command on the server for your site, in the root directory rename index.php to index.old, and copy the string that is random characters into a new index.php file, the one python would be severing if you ran the command. The string to copy is r.wfile.write(‘xxx’), where xxx is random characters.

Then click enter and you should have a crt file, you can delete the new index file and rename the old one.

Now you’ll need to login to cPanel.

Go to the SSL/TLS Manager.

Click Generate, view, upload, or delete your private keys., and upload the domain.key file. It should be in your ssl directory.

Click Generate, view, upload, or delete SSL certificates., and then upload the signed.crt file. After it uploads go back and click Install.

In the Certificate Authority Bundle: (CABUNDLE) enter the “Let’s Encrypt Authority X1 (IdenTrust cross-signed)” from here, click the txt link, if it doesn’t work use “Let’s Encrypt Authority X2 (IdenTrust cross-signed)”.

Click install and it should work.

Don’t know how to do it with DirectAdmin. If you pay 15 dollars a month for a VPS with DirectAdmin, I can tell you.

Update
If you don’t have a .htaccess file, like the one that WordPress uses, it won’t work.

<br><IfModule mod_rewrite.c><br>RewriteEngine On<br>RewriteBase /<br>RewriteRule ^index.php$ - [L]<br>RewriteCond %{REQUEST_FILENAME} !-f<br>RewriteCond %{REQUEST_FILENAME} !-d<br>RewriteRule . /index.php [L]<br></IfModule><br>

That should do the trick.

Update #2
Oh yeah the cPanel instructions might be different depending on your host. A Small Orange is different then BUYSHARED, I’m guessing they use a different version. Nope, they are the same version.

Update
BUYSHARED has Let’s Encrypt in their cPanel. Looks like it’ll do everything for you.

This is going to take a while

Making a copy of my micro SD card using dd. Restoring just one partition doesn’t work, says over 600 mb/s. The old card is 8 GB. So it’ll take a while to write that to the new card at under 10 mb/s.

Only have Internet on phone until it’s done. I could put the old card in until it’s done.

It’s done.