Posts

Showing posts from 2018

Drupal 7 Create Node With Specific NID using PHP

$node = new stdClass(); $node->type = "page"; // Sets some defaults. Invokes hook_prepare() and hook_node_prepare(). node_object_prepare($node); // Or e.g. 'en' if locale is enabled. $node->language = LANGUAGE_NONE; $node->uid = 234; // Status is 1 or 0; published or not. $node->status = 1; // Promote is 1 or 0; promoted to front page or not. $node->promote = 0; // Comment is 0, 1, 2; 0 = disabled, 1 = read only, or 2 = read/write. $node->comment = 0; $node->nid =123; $node->title = 'title 123'; $node->is_new = true; $node = node_submit($node); // Prepare node for saving node_save($node);

Cron on alternate weeks - Simple hack

The below cron entry will run a script file at 5am on every Sunday. 0 5 * * 0 sh script.sh Simply include the below three lines in your script to swap your actual code file with an empty file on every run. cp GetData.php Temp.php mv Swp.php GetData.php mv Temp.php Swp.php GetData.php = actual code Swp.php = blank file This will run the code only on alternate weeks.

iPhone - Keeping WiFi Connected

If your iPhone suddenly starts disconnecting from WiFi every time it's locked — maybe due to an update — the solution is to reset (only) your Network Settings .

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).

The Discerning Investor

Which Came First - The Strategy or The Stock Graham's framework is designed to be sector independent, and comes very highly recommended. But his rules are extremely selective and very few stocks clear them. That's precisely why they give great results. But Graham's framework is also unpopular for the same reason; because few stocks fare well against it. (It's not much use for writing articles. In short, good for investors; bad for analysts!) In the end, it's a personal choice. Does one pick stocks based on a preferred strategy, or a strategy based on one's preferred stocks? The answer - for both investors and analysts - is obvious, and they're not the same. GAAP vs Non-GAAP Earnings A businessman interviewing job applications for the position of manager asked each applicant only one question, "What is two plus two?" The first interviewee was a journalist. His answer was, "Twenty-two". The second was a social worker. She said,

htaccess rewrite for https and www

RewriteCond %{ HTTPS } off # First rewrite to HTTPS: # Don't put www. here. If it is already there it will be included, if not # the subsequent rule will catch it. RewriteRule .* https ://%{ HTTP_HOST }%{ REQUEST_URI } [ L , R = 301 ] # Now, rewrite any request to the wrong domain to use www. # [NC] is a case-insensitive match RewriteCond %{ HTTP_HOST } !^ www\. [ NC ] RewriteRule .* https :// www .%{ HTTP_HOST }%{ REQUEST_URI } [ L , R = 301 ]

Checking strpos - PHP's idea of BPD

Suppose you need to make sure that a certain path does not contain a certain string. 1. strpos($CurrentPath,'node/12345/') < 0 Will not fire because the return value is FALSE. 2. strpos($CurrentPath,'node/12345/') == FALSE Will fire even when the path starts with the string because a return value of 0 evaluates to FALSE. 3. !(strpos($CurrentPath,'node/12345/') > -1) Finally!

CURL not working — check for HTTPS before emulating browser requests

CURL requests to certain URLs that were working fine seemed to stop working overnight. The requests seemed to go through fine on the browser. After monitoring network requests and getting CURL to emulate browser requests using user agent headers, it turned out that the said server had simply stopped servicing HTTP requests. Browser requests were being redirected to HTTPS. CURL requests were not. All that needed to be done was convert the HTTP requests to HTTPS.

Facebook Invite Console Script

// Step 0: Open post likes // Step 1: Run load all function clickSeeMore() { var buttons = document.getElementsByClassName('uiMorePagerPrimary'); if (buttons[0] != null) { buttons[0].focus(); buttons[0].click(); setTimeout(clickSeeMore, 2000); } } clickSeeMore(); // Step 2: Run invite function clickInvite() { var buttons = document.getElementsByClassName('_42ft'); for (var i = 0; i < buttons.length; i++) { if(buttons[i].getAttribute('ajaxify') != null) { if(buttons[i].getAttribute('ajaxify').indexOf('invite') != -1) { buttons[i].focus(); buttons[i].click(); setTimeout(clickInvite, 1000); break; } } } } clickInvite();