Reading the dictionary but every time I see a word I don't know in a definition I stop to look it up.
seen from United States
seen from United States
seen from Malaysia
seen from Singapore
seen from China
seen from Philippines

seen from Malaysia
seen from United States
seen from Russia

seen from Malaysia
seen from China
seen from China
seen from United States

seen from Australia
seen from Morocco

seen from United States
seen from China
seen from Netherlands

seen from China
seen from United Kingdom
Reading the dictionary but every time I see a word I don't know in a definition I stop to look it up.
Explore the R recursion concept, its examples, applications and features. R recursive function break down the problem into the smallest possible components.
Recursion In Our Life, Which Is Sometimes A Curse.
প্রোগ্রামিং এর অন্যতম এক শক্তিশালী অস্ত্র হলো Recursion বা Recursive Function। যেটা বলতে আমরা বুঝি ঘরের ভেতরে ঘর, সেই ঘরের ভেতরে আবার একই ঘর। কিংবা অর্ণবের সেই পরচিত গান :- ” বাক্সে বাক্সে বন্দী বাক্স, বাক্সে বাক্সে বন্দী বাসা “। অথবা শিল্পীর ক্যানভাসে আঁকা কোনো এক প্রাকৃতিক দৃশ্য যেখানে ওই একই শিল্পীকে ওই একই ছবি আঁকতে দেখা যাচ্ছে, আবার সেই ছবির ভেতরের ছবিতেও ওই একই জিনিসের পুন:রাবৃত্তি। এভাবে চলতে থাকবে একটি নির্দিষ্ট সময় পর্যন্ত যতক্ষণ একটি নির্দিষ্ট শর্ত পূরণ না হয়। উফফ কি যন্ত্রণা !!! আবার সেই Loop, আবার সেই Condition। কিন্তু তখন কেমন মনে হবে, যদি শুনি কারও নিজের জীবনেই চলতে পারে এই Recursion প্রক্রিয়া। যেমন : মনে করি অতীতে কেউ কোন একটা ভুল করেছিলো যার মাশুল তাকে আজও দিতে হচ্ছে, এখন সে যদি ওই ভুল শুধরানোর জন্য তার কারণ খুঁজতে গিয়ে দেখতে পেলো ওই ভুলের কারণ হলো আরও একটা ভুল। একইভাবে পরের ভুলটার কারণও কোনো একটা ভুল। শুধু ভুল আর ভুল আর ভুল। হায়রে, ভুলে ভুলে মানুষের জীবন গদ্যময়। তাহলে কি করে ওই মানুষটা পারবে এতো গুলো ভুলের সমাধান করতে। পরাবাস্তব প্রোগ্রামিং জগতের Recursion বাস্তব এই জগতের জন্য আর কিছুই না, শুধুমাত্র একটা অভিশাপ।
The maximum call stack size
최대 호출 스택 사이즈
당신은 당신이 만든 자바스크립트 엔진을 어떻게 많이 재귀 호출할 수 있는 지 궁금하지?
많은 재귀 함수 호출은 어떻게?
다음과 같은 함수로 알수 있다.(Ben Alman의 gist에서 영감을 얻었다.)
function computeMaxCallStackSize() { try { return 1 + computeMaxCallStackSize(); } catch (e) { // Call stack overflow return 1; } }
Node.js, Firefox, Chrome 3가지의 결과
Node.js: 11034
Firefox: 50994
Chrome: 10402
이 숫자가 의미하는 것은 무엇일까? Mr. Aleph는 V8엔진은 나에게 pointed out 이다, 재귀 호출의 숫자는 당신이 두개의 수량의 지적을 만들수 있다: stack의 사이즈와 stack frame의 사이즈이다(파라미터와 로컬 변수들이 들어있는).computeMaxCallStackSize()의 로컬 변수를 추가의 의해 latter는 verify이 할수 있다. 그거슨 로우 넘버를 리턴할 것이다.
ECMAScript 6의 Tail 호출 최적화
ECMAScript 6에서는 tail call을 최적화 할 것이다 : 만약 함수 호출이 함수안의 마지막 행동이라면, subroutine call이 아닌 “jump”를 통해 처리 될것이다. 즉 당신이 computeMaxCallStackSize()의 조금 재 작성하는 경우 그것은 ECMAScript 6(strict mode)에서 영원히 실행 될 것이다.
function computeMaxCallStackSize(size) { size = size || 1; return computeMaxCallStackSize(size + 1); }
출처 : http://www.2ality.com/2014/04/call-stack-size.html
C
PHP mySQL Recursive Replace String (Entire DB) + Sanitizing User Input
I've been working on a store front website and a CMS (Content Management System) that I created for a client and I learned the hard way that I should have incorporated some sort of input sanitation (oops!). Long story short, I thought it would best to leave direct HTML input enabled in my CMS to facilitate stuff like lists, line breaks, images, etc (::Face-Palm::). However I was still really noobish and didn't consider what those little &'s and whatnot would do to the actual HTML. Since the client had already entered a lot of data for her products, starting over was not an option. The Solution: Build a PHP script that would recursively replace every instance of the offending character. Please note that I made some changes to the the following script in an effort to clean it up for this post, so there is a slight chance that it could throw an error or have an unexpected result.
//Set variables: $dbName = "myDB"; $find = "&"; $replace = "&"; //Return Tables: $result = mysql_list_tables($dbName) or die(mysql_error()); $num_rows = mysql_num_rows($result); //Iterate over tables: for ($i = 0; $i < $num_rows; $i++) { $table = mysql_tablename($result, $i); //Output table name: echo "Table: ".$table . ":<br/>"; //Return fields: $result2 = mysql_query("select * from $table limit 1"); $numOfCols = mysql_num_fields($result2); //Iterate over fields: for($i2=0; $i2<$numOfCols; $i2++){ $res = mysql_query("select * from $table"); $fieldName = mysql_field_name($res, $i2); //Output field name: echo " ".$fieldName . "<br/>"; mysql_query("UPDATE $table SET $fieldName = replace($fieldName,'$find','$replace')") or die(mysql_error()); } } //Clean up memory: mysql_free_result($result); mysql_free_result($result2);
Pretty simple huh? Just replace the variables ($dbName, $find, $replace) and include your SQL connection info/credentials in the beginning of the script and you should be good. The DB I used this on wasn't very big, so this might not be practical for larger DBs - if you do use this on a larger DB make sure that you increase PHP's timeout and memory allocation. Also, one could include multiple find/replace in arrays and iterate through those by replacing lines 3 and 4 with:
$find = array("&","<",">"); $replace = array("&","<",">");
And replace line 27 with a foreach loop to iterate through the $find array:
foreach($find as $key => $val){ mysql_query("UPDATE $table SET $fieldName = replace($fieldName,'$find[$key]','$replace[$key]')") or die(mysql_error()); }
Again, the above has not been tested so I'm not to blame for anything here. As with any piece of code you get from the internet - TEST IT FIRST! Just setup a dummy DB + tables and check it out. While this issue resulted in a nice little learning experience and a piece of code that will surely be useful in the future, it could have been easily avoided. There are many different methods built into PHP to sanitize user input and even more user created scripts. I would suggest that anytime you have a string going into a table you use the mysql_real_escape_string() method. The sort of sanitation that this function provides is crucial as it helps eliminate the potential for an SQL Injection attach. To clean up strings for HTML use htmlspecialchars(). I could have used for my CMS as it would have replaced all of the 'special' characters with HTML codes, but that wouldn't have been ideal, considering I wanted to allow HTML input but still prevent my client from using characters that could break the website. Ah, but the hindsight is strong within me - so strong that I actually went back to rectify the issue (after I had to run this script about 3-4 more times, lol). The ultimate solution would have (and is), to of used something similar to CKEditor or similar WYSIWIG (What You See Is What You Get) text/HTML editor, as on of my other problems was the fact that I was trying to retain HTML capabilities for a client that didn't know any HTML!
getDirs() - Recursively add directory with files to an array - PHP
I needed a function that would recursively drill down into a directory, returning an array with the directory structure and files. I also needed the function to filter out directories and files that I didn't want listed (in addition to the parent directory markers). Oddly enough there wasn't much out there to provide examples of how to do this and some of the code snippet I found were just excessively big and complex, so I made getDirs():
$directories = getDirs($path); //This is the function call, the only argument is the $path of the dir. function getDirs($path){ $results = ''; //Open the path: if ($handle = opendir($path)) { //Iterate through the dir: while (false !== ($file = readdir($handle))) { //Regex to filter out files and unwanted directories (input and results) - manipulate the second preg_match() as needed: if (!preg_match("/\./", $file) && !preg_match("/^(input|results).*/i", $file)) { $dir = $path.$file."/"; $results[$file] = getDirs($dir); $results[$file]["Path"] = $dir; } //Only add files with the .php extension - you can change this to whatever extension or something like: "/\.[a-z0-9_-]$/i" to match any files. elseif(preg_match("/\.php$/i", $file)){ $results[$file] = $path.$file; } } closedir($handle); } return $results; }