Jquery selector with pure javascript

a month ago

The only thing i wanted on pure js from jquery was the selector and my code not to break everytime a div is missing when i am adding events or using them on something.

So after a long search on the Internet i couldn't find anything other the selector...

So i figured out one way is to make a fake element if the real one does not exist.

The fake one is never placed on the html and every event on the fake element will get ignored!

Unless you are having "unknown" elements you should never have any issues :)

//jquery selector 
//using '$' will select 1 item
//and using $$ will select all items
function $(s) {
  //if doesn't exist throw a fake element to ignore all errors
  return (!document.querySelector(s)) ? document.createElement("unknown") : document.querySelector(s);
function $$(s) {
  //same logic as $
  return (!document.querySelectorAll(s)) ? document.createElement("unknown") : document.querySelectorAll(s);
//add events using this $(example).on("click",function(){});
Object.prototype.on = function(name, fn) {
  //don't create the event if element is unknown
  return (this.tagName.toLowerCase() !== "unknown") ? this.addEventListener(name, fn) : false;

Now if there is no element with that name the whole js won't break!

Using $ will always search for 1 element for more u have to use $$

We all have problems with mobile debuging

5 months ago

I couldn't find anything better for webpage debugging tool without using a USB...

So i was using a div all the time on the HTML...

I don't know if this is the best way but since it doesn't hurt the project and it doesn't give bad results i published it in NPM

Hope it helps other people as it did for me :)

Github link

NPM link

Apache config for allowing only specific ips from control panel for drupal

a year ago

This will run recursively for user path

<LocationMatch "/user">
 Order deny,allow
 deny from all
 allow from [YOURIP]

And this will throw 404 Drupal stupid /?q=user path...

RewriteEngine on
RewriteCond %{QUERY_STRING} ^(.*)?q=user(.*)$
RewriteRule ^ - [L,R=404]

I made a mini web app with pure nodejs for tinkerboard

a year ago

It should work fine for raspberry and other Debian based Linux!

The app shows tinkerboard's status (temp,cpu usage,ram usage,packages to update)

I made a lot of comments explaining how it works so i hope its easy for someone to get to know nodejs or how http works without any framework.

Click For The Repo

SQLite Database update on file change

a year ago

Here is how i use SQLite to grab new data on file change before someone calls it(from the routes).

I use this on express js you can set it up on app.js.

All the database will be stored into one variable and you can use javascript commands to manage/filter/split whatever you want as long as you don't want to access the db for adding or do any other stuff with it.

var Database = require('better-sqlite3'),
    db = new Database('./data/db.db'),
    database = [];

function data(){
   database = db.prepare('SELECT * FROM items').all;


  console.log(`There was a ${s} in the database`);

Just to be safe it's always nice to have these options on

db = new Database('data.db',{readonly:true,fileMustExist: true})

{readonly: true} blocks SQLite commands from executing like `insert`

{fileMustExist: true} throws error if you mess up with the location of the database instead of creating a new one