Posts

Showing posts with the label Programming

Linux Firewall (iptables) commands for DDoS attacks

Image
You may need to check your logs and block some IPs manually on a regular basis. Always use ipsets for efficient filtering, especially when dealing with larger numbers of entries. sudo ipset create gvset1 hash:ip sudo ipset create gvset2 hash:net sudo iptables -A INPUT -m set --match-set gvset1 src -j DROP sudo iptables -A INPUT -m set --match-set gvset2 src -j DROP For example, any IP that has more than 10 access denied or page not found errors in the last 24 hours and are not Google or MSN IPs. Ensure that the hosts do not resolve to Google search, MSN search or the Amazon crawler. It's usually ok to resolve to Amazon AWS. Use at your own risk. This method may block some legitimate ISPs. Also block the SSH port ( 22 ) on your server hosting provider firewall, if possible. Important: Make sure your own IP is not in a range before running the commands. Also ensure that any IPs within the googlebot IP range below, are removed. sudo iptables -D INPUT -s 66...

Drupal 7 Stop User Registration Emails

Image
Using A Module Mailcontrol Using Drush drush vset user_mail_register_no_approval_required_notify FALSE All Registration Variables user_mail_register_admin_created_notify user_mail_register_pending_approval_notify user_mail_register_no_approval_required_notify user_mail_password_reset_notify user_mail_cancel_confirm_notify

Show Path of Current Wallpaper in Mac OS X

Image
Here’s how to show the file path to the currently active wallpaper in Mac OS X: defaults write com.apple.dock desktop-picture-show-debug-text -bool TRUE;killall Dock

Notes on Enlarging the SSD in CentOS (IONOS Cloud Server)

Image
The steps on Customizing the Logical Volume After Enlarging the SSD in CentOS (Cloud Server) are quite thorough. But for some reason, the growpart option did not work and the manual option had to be used instead. But the manual option works fine, if all the steps are followed correctly; especially the restart part.

Sometimes people get lucky

Image
Doesn't mean much (actual scene removed from YT).

Real Engineers and Computer Programmers

Image
Linus Torvalds Explaining why people like him: 1. Require silence to code. 2. Interact through buffers. 3. Write elegant code . 4. Are grounded and solution-oriented. 5. May be perceived as "not nice".

Comparing C to Machine Language

Image
This video nicely demonstrates something I've been curious about for 24 years now; how high level languages translate to assembly code. (even though I hate code that has opening braces on the same line as the code) Observations: 1. C and ASM are very similar structurally, which means C does not lose any power through abstraction. 2. C abstracts the grunt work of remembering addresses etc so one can focus on the actual algorithm, and is also better structured which greatly improves readability. 3. ASM is not really that hard and is in fact, structurally simpler than C; somewhat similar to the original BASIC (basica.exe).

Shortest Code For Generating Prime Numbers

Image
<?php for ($i = 1; $i < 1000; $i++) {     $print = TRUE;        // Optimized till square roots     for ($j = 2; ($j*$j) <= $i; $j++)     {         $print = FALSE;         if ($i % $j == 0)             break;                $print = TRUE;     }     if ($print)         print $i.','; } ?> <? // Here's a little trick I learnt from a friend almost 30 years ago // Counting Prime numbers $StartTime = time(); $PrimeCount=0; for ($i=1; $i<200000; $i++) { $IsPrime = true; for ($j=2; ($j*$j)<=$i; $j++) { if (($i % $j) == 0) $IsPrime=false; } if ($IsPrime) $PrimeCount++; } $TimeTaken = (time() - $StartTime); echo 'Counted '.$PrimeCount.' prime numbers in '.$TimeTaken.' seconds.'.PHP_EOL; // Ga...

The Essence of Computer Programming

Computers are basically for the automation of repetitive work. So programming computers is essentially the art of automation of repetitive work using loops. Thus, the most essential thing one needs to understand to program computers is how to write loops. That covers everything essential. PS: Recursion is assumed here to just be a more advanced form of a loop, which is just a more elegant solution for certain types of problems.

The Software Industry and Computer Programmers

A google employee once wrote an article in which he said something like: "Often we would interview a programmer who had an incredible amount of knowledge on a wide range of subjects, but couldn't program Hello World in any language." It's really amazing how many people in the software industry simply know nothing about programming computers. We're talking about core technical people such as Product Managers - not people in unrelated departments such as marketing - who have big plans and strong opinions on everything related to technology, but lack basic technical skills. To put it in perspective, imagine an entire department of road planning where no one really knows to drive.

A more reliable interview process for computer programmers

One of the first things I noticed in the software industry, was that verbal technical interviews tended to highly unreliable. On many occasions, I had observed average performers at work clear interviews that top performers had not. The former didn’t know much about programming computers, but were very good at clearing interviews. They had the confidence and knew the answers to all the usual interview questions, which they usually brushed up on the previous day. As an interviewer from Google once remarked, some candidates were often extremely knowledgeable in interviews, but in practice, could not code the most basic programs in any language. The problem is that verbal technical interviews rely largely on communication and confidence. Confidence is normally considered a sign of ability but the two are not actually correlated. Studies have shown that mildly capable people often tend to be more confident than extremely capable people ( Dunning–Kruger effect ). But as the average perf...

Open Source Software is more secure

Image
It's amusing how even "Architects" in MS Product Companies think Open Source Software is less secure. That's like saying a bank is safer if it's in a remote location. Or locks from unknown companies are safer than locks from known ones. Proprietary Software relies on loopholes not being found. Open Source Software relies on not having loopholes. 2022 Update Given below is a slightly better explanation of this Security Through Obscurity (STO) fallacy, by the LockPickingLawyer . There may be a market for locks with completely transparent cases, i.e., the open source software model. Limit obvious loopholes and demonstrate acceptable levels of security, by eliminating obscurity. But isn't anonymity another form of Security Through Obscurity ? "I don't think my name adds or subtracts from my message. I have no desire to be famous or well-known... I had a lot of big well-known companies as clients, and i didn't want my online presenc...

The Code Is The Design

Image
Why programming is about focus, and not hours of work or lines of code. Also, why you can't replace a racehorse with two cart horses. Most people don’t understand what a computer really is. It’s the modern equivalent of a magic wand. Its power is only limited by the person wielding it.   Jack Reeves From Slashdot The Code Is The Design "In 1992 C++ Journal published an essay by Jack W. Reeves called 'What Is Software Design?' Many credit this essay as being the first published instance of assertions such as 'programming is not about building software; programming is about designing software" From What is Software Design? o Real software is incredibly cheap to build, and getting cheaper all the time as computers get faster. o Real software is incredibly expensive to design. This is true because software is incredibly complex and because practically all the steps of a software project are part of the design process. o Programming is a design...

Fibonacci solutions :)

///  Impressive solution static   void  Main2( string [] args) {      int  t1 = 0, t2 = 0, i = 0, j = 1, count = 15;      Console .WriteLine(i);      Console .WriteLine(j);      for  ( int  a = 1; a < count; a++)     {          int  localval;          if  (a == 1)         {             t1 = i;             t2 = j;         }          else         { ...