Programming / Re: Create A Nested Lists Of Categories In Laravel 5 by jacob05(m): 10:47am On Aug 26, 2015 |
Make things simple for yourself... it won't hurt creating another Model for CategoryItem Category
namespace App;
use Illuminate\Database\Eloquent\Model;
class Category extends Model { protected $guarded = ['id'];
public static $table = 'categories';
public function children() { return $this->hasMany('App\CategoryItem', 'parent_id'); } }
CategoryItem
namespace App;
use Illuminate\Database\Eloquent\Model;
class CategoryItem extends Model { protected $guarded = ['id']; public static $table = 'categoryitems';
public function pareet() { return $this>belongsTo('App\CategoryItem', 'parent_id'); } }
Migratations
<?php
class Create_Categories_Table {
/** * Make changes to the database. * * @return void */ public function up() { //
Schema::table("categories", function($table){ $table->create(); $table->increments('id'); $table->string('name', 255); $table->timestamps(); });
}
/** * Revert the changes to the database. * * @return void */ public function down() { // Schema::drop("categories" ; }
}
<?php
class Create_CategoryItems_Table {
/** * Make changes to the database. * * @return void */ public function up() { //
Schema::table("categoryitems", function($table){ $table->create(); $table->increments('id'); $table->increments('parent_id'); $table->string('name', 255); $table->string('slug', 255); $table->timestamps(); $table->foreign('parent_id')->references('id')->on('categories'); });
}
/** * Revert the changes to the database. * * @return void */ public function down() { // Schema::drop("categoryitems" ; }
}
The Above Might not run but should explain the logic 1 Like |
Jobs/Vacancies / Re: Andela: IT Training And Job by jacob05(m): 8:38am On Aug 26, 2015 |
Ramos16: huh like instruction of where to stay? Naa |
Jobs/Vacancies / Re: Andela: IT Training And Job by jacob05(m): 8:26am On Aug 26, 2015 |
tgmservice: where u booked on friday, and what location do you stay instructions in invitation msg. |
Jobs/Vacancies / Re: Andela: IT Training And Job by jacob05(m): 8:00pm On Aug 25, 2015 |
Got an invite.. Booked for Friday.... Just going for a walk. No High Hopes ![cool](https://www.nairaland.com/faces/cool.png) |
NYSC / Re: 10 Reasons Why Nysc Should Be Voluntary by jacob05(m): 2:42pm On Aug 25, 2015 |
taiwolusol:
8. IT IS TOO EXPENSIVE How much do the government (State and Federal) spend on the seemingly unnecessary Programme. I might not be so good at mathematics, but I can come with a rough estimate of about #350K on each corp member. Multiply that by close to a hundred thousand graduates that go through the scheme a year and you’ll have a feel of how much money the government is not getting value for. Tax payer’s money they call it.
Nope. NYSC is quite cheap ![wink](https://www.nairaland.com/faces/wink.png) calculate the cost of employing teachers 3 Likes |
Celebrities / Re: Wizkid, Pasuma, Wande-Coal And Chidinma At Star Music Trek Ibadan by jacob05(m): 2:28pm On Aug 25, 2015 |
paso.. lol 1 Like |
Programming / Re: Developing An Idea Into An Application by jacob05(m): 9:02am On Aug 20, 2015 |
DonSegmond: Anywhere from N10,000 to N1,000,000,000. |
Programming / Re: President Buhari Voice Recognition Program - Contest For 50,000 Naira by jacob05(m): 11:08pm On Aug 19, 2015 |
MuhammaduBuhari:
that implies that he is gaddamn troll too. so na troll vs troll be that now. checkmate.. lolx |
Programming / Re: President Buhari Voice Recognition Program - Contest For 50,000 Naira by jacob05(m): 11:02pm On Aug 19, 2015 |
danjumakolo:
Boy,i ain't gat no time for that now. I only stumbled on the thread and felt I shud contribute to husstlers here.This was fetched from my past old projects.Even the way I posted should give you a clue that, this is just a passer by
I have more important schedules to deal with.
Sorry if i hurt you.
Hope this helps
hmmm.. your username says it all.. Thanks for "Trolling" by... |
Programming / Re: President Buhari Voice Recognition Program - Contest For 50,000 Naira by jacob05(m): 10:31pm On Aug 19, 2015 |
danjumakolo:
U chop craze ba? U run the code ne? Abi e pass yo.level ![angry](https://www.nairaland.com/faces/angry.png) |
Programming / Re: Another Php Algorithm Help Needed by jacob05(m): 7:26pm On Aug 19, 2015 |
|
Programming / Re: Another Php Algorithm Help Needed by jacob05(m): 7:13pm On Aug 19, 2015 |
<?php function timesTwo($n) { return($n * 2); }
echo implode(array_map("timesTwo", str_split("1234480" ))); //OR (going crazy) echo implode(array_map(function($n){ return($n * 2);}, str_split("1234480" ))) ;
|
Programming / Re: Please Kindly Help With This JSON Code by jacob05(m): 6:11pm On Aug 19, 2015 |
ptassystems: Am trying to use it on the contact page of a website, but whenever the contact form is filled, the message posted are not delivered to the mail. Only an empty message is delivered.
The Email, Name, Subject and Message sent are not delivered, just an empty mail. probably you should check your HTML form... or paste it |
Programming / Re: Tic Tac Toe Online Game With AI by jacob05(m): 5:38pm On Aug 19, 2015 |
dhtml18: ^^^joblessness at its peak! Haaaaa Haaaa... When bosses no give work nko? |
Jobs/Vacancies / Re: Andela: IT Training And Job by jacob05(m): 12:07pm On Aug 19, 2015 |
Scored 772 ![wink](https://www.nairaland.com/faces/wink.png) 1 Like |
Programming / Re: President Buhari Voice Recognition Program - Contest For 50,000 Naira by jacob05(m): 8:22am On Aug 18, 2015 |
danjumakolo:
package com.example.android.apis.app; import com.example.android.apis.R; import android.app.Activity; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.os.Bundle; import android.os.Handler; import android.speech.RecognizerIntent; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.Spinner; import android.widget.SpinnerAdapter; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; import java.util.List; /** * Sample code that invokes the speech recognition intent API. */ public class VoiceRecognition extends Activity implements OnClickListener { private static final String TAG = "VoiceRecognition"; private static final int VOICE_RECOGNITION_REQUEST_CODE = 1234; private ListView mList; private Handler mHandler; private Spinner mSupportedLanguageView; /** * Called with the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mHandler = new Handler(); // Inflate our UI from its XML layout description. setContentView(R.layout.voice_recognition); // Get display items for later interaction Button speakButton = (Button) findViewById(R.id.btn_speak); mList = (ListView) findViewById(R.id.list); mSupportedLanguageView = (Spinner) findViewById(R.id.supported_languages); // Check to see if a recognition activity is present PackageManager pm = getPackageManager(); List<ResolveInfo> activities = pm.queryIntentActivities( new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); if (activities.size() != 0) { speakButton.setOnClickListener(this); } else { speakButton.setEnabled(false); speakButton.setText("Recognizer not present" ; } // Most of the applications do not have to handle the voice settings. If the application // does not require a recognition in a specific language (i.e., different from the system // locale), the application does not need to read the voice settings. refreshVoiceSettings(); } /** * Handle the click on the start recognition button. */ public void onClick(View v) { if (v.getId() == R.id.btn_speak) { startVoiceRecognitionActivity(); } } /** * Fire an intent to start the speech recognition activity. */ private void startVoiceRecognitionActivity() { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); // Specify the calling package to identify your application intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName()); // Display an hint to the user about what he should say. intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speech recognition demo" ; // Given an hint to the recognizer about what the user is going to say intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); // Specify how many results you want to receive. The results will be sorted // where the first result is the one with higher confidence. intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5); // Specify the recognition language. This parameter has to be specified only if the // recognition has to be done in a specific language and not the default one (i.e., the // system locale). Most of the applications do not have to set this parameter. if (!mSupportedLanguageView.getSelectedItem().toString().equals("Default" ) { intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, mSupportedLanguageView.getSelectedItem().toString()); } startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE); } /** * Handle the results from the recognition activity. */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == VOICE_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) { // Fill the list view with the strings the recognizer thought it could have heard ArrayList<String> matches = data.getStringArrayListExtra( RecognizerIntent.EXTRA_RESULTS); mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, matches)); } super.onActivityResult(requestCode, resultCode, data); } private void refreshVoiceSettings() { Log.i(TAG, "Sending broadcast" ; sendOrderedBroadcast(RecognizerIntent.getVoiceDetailsIntent(this), null, new SupportedLanguageBroadcastReceiver(), null, Activity.RESULT_OK, null, null); } private void updateSupportedLanguages(List<String> languages) { // We add "Default" at the beginning of the list to simulate default language. languages.add(0, "Default" ; SpinnerAdapter adapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item, languages.toArray( new String[languages.size()])); mSupportedLanguageView.setAdapter(adapter); } private void updateLanguagePreference(String language) { TextView textView = (TextView) findViewById(R.id.language_preference); textView.setText(language); } /** * Handles the response of the broadcast request about the recognizer supported languages. * * The receiver is required only if the application wants to do recognition in a specific * language. */ private class SupportedLanguageBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, final Intent intent) { Log.i(TAG, "Receiving broadcast " + intent); final Bundle extra = getResultExtras(false); if (getResultCode() != Activity.RESULT_OK) { mHandler.post(new Runnable() { @Override public void run() { showToast("Error code:" + getResultCode()); } }); } if (extra == null) { mHandler.post(new Runnable() { @Override public void run() { showToast("No extra" ; } }); } if (extra.containsKey(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES)) { mHandler.post(new Runnable() { @Override public void run() { updateSupportedLanguages(extra.getStringArrayList( RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES)); } }); } if (extra.containsKey(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE)) { mHandler.post(new Runnable() { @Override public void run() { updateLanguagePreference( extra.getString(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE)); } }); } } private void showToast(String text) { Toast.makeText(VoiceRecognition.this, text, 1000).show(); } } }
![undecided](https://www.nairaland.com/faces/undecided.png) |
Programming / Re: Tic Tac Toe Online Game With AI by jacob05(m): 12:27am On Aug 17, 2015 |
Can't sleep, ![undecided](https://www.nairaland.com/faces/undecided.png) , so i decide to view your code... (was afraid before..lol... make person head no come turn...) I observe you repeat similar try .... catch blocks which greatly increase the size of your code (bad) and causes a lot of duplication... so I'd like to suggest this.. (Not Tested.... but should be of help.... i guess ![wink](https://www.nairaland.com/faces/wink.png) ) CheckWon function checkWon(who,xy, a1,a2){ var values = new Array(5); values[0] = table[xy[0]][xy[1]]; values[1] = table[xy[0]+ a1[0]][xy[1] + a2[0]]; values[2] = table[xy[0]+ a1[1]][xy[1] + a2[1]]; values[3] = table[xy[0]+ a1[2]][xy[1] + a2[2]]; values[4] = table[xy[0]+ a1[3]][xy[1] + a2[3]]; console.log(values); if (document.getElementById(values[0]).getAttribute('played') == who && document.getElementById(values[1]).getAttribute('played') == who && document.getElementById(values[2]).getAttribute('played') == who && document.getElementById(values[3]).getAttribute('played') == who && document.getElementById(values[4]).getAttribute('played') == who)//AI has an horizontal winning move { for(var x= 0; x < values.length; x++) { $('#'+values[x]).css('background', 'url(img/tile' + who + 'W.png)'); $('#'+values[x]).css('background-size', '100%,100%'); $('#'+values[x]).css('background-size', 'cover'); } endGame(who); return; }
}
Usage try { //------Check tiles diagonally rightways------- checkWon(who,getXY(tileID), [1,2,3,4],[1,2,3,4]); } catch (e) { }
try { //------Check tiles vertically------- checkWon(who,getXY(tileID), [1,2,3,4],[0,0,0,0]); } catch (e) { }
try { //------Check tiles horizontally------- checkWon(who,getXY(tileID), [0,0,0,0],[1,2,3,4]); } catch (e) { }
try { //------Check tiles diagonally leftways------- checkWon(who,getXY(tileID), [1,2,3,4],[-1,-2,-3,-4]); } catch (e) { }
This Can also be tweaked to work for other functions like checkWinningMoveAI and the rest... |
Programming / Re: Tic Tac Toe Online Game With AI by jacob05(m): 1:04pm On Aug 16, 2015 |
|
Programming / Re: Tic Tac Toe Online Game With AI by jacob05(m): 11:21am On Aug 16, 2015 |
Wow, Lovely Game i must say... thumbs up FincoApps.. would love to do AI too when i grow up ![grin](https://www.nairaland.com/faces/grin.png) I'd love if when Daddy plays, some kind of glow fades in and out for probably 2000ms on the played tile. This is to easily know Daddy's current move when the played tiles are many. But I think the bug isn't fixed, on the site, yet... 1 Like
|
Programming / Re: Help On This Simple Script by jacob05(m): 7:36pm On Aug 15, 2015 |
you did not assign value to lbl by mistake.. try indenting your codes too, bugs are, sometimes, easily fixed with proper indentation function count() { var lbl = document.getElementById('lbl'); for (i=0; i<10; i++) { lbl.innnerHTML+= i+'<br>'; } }
<button type='button' onclick='count()'>start counting </button> <div id='lbl'></div>
1 Like |
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 9:47pm On Aug 14, 2015 |
|
Programming / Re: Help Construct An Algorithm In Php Code by jacob05(m): 7:06pm On Aug 14, 2015 |
-------------------------------------- | PHP BENCHMARK SCRIPT | -------------------------------------- Start : 2015-08-14 19:04:28 Server : localhost@? PHP version : 5.5.12 Platform : WINNT -------------------------------------- test_Kidstell_method : 0.016 sec. test_babatope88_method : 0.002 sec. -------------------------------------- Total time: : 0.018 sec.
-------------------------------------- | PHP BENCHMARK SCRIPT | -------------------------------------- Start : 2015-08-14 19:04:28 Server : localhost@? PHP version : 5.5.12 Platform : WINNT -------------------------------------- test_Kidstell_method : 0.017 sec. test_babatope88_method : 0.005 sec. -------------------------------------- Total time: : 0.022 sec. --------------------------------------------
Unable to test DonSegmond's Method because of my php version (requires 5.6.0).. 1 Like |
Programming / Re: Help On C# by jacob05(m): 6:03pm On Aug 14, 2015 |
|
Programming / Re: Help Construct An Algorithm In Php Code by jacob05(m): 9:50pm On Aug 13, 2015 |
funny enough... i didn't read the whole question before posting my solution... ![grin](https://www.nairaland.com/faces/grin.png) @Kidstell nice one |
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 8:20pm On Aug 13, 2015 |
dhtml18: The master-troll is now back full-force(from a trollin vacation) on this thread. I shall be launching my IDE very soon and start testing out all these jagbajantis you call c# codes to see if they are authentic before i move a motion for your banishment from this board! lolz.. Pls do sir !!!. |
Programming / Re: Help Construct An Algorithm In Php Code by jacob05(m): 5:24pm On Aug 13, 2015 |
You're welcome |
Programming / Re: Help Construct An Algorithm In Php Code by jacob05(m): 4:27pm On Aug 13, 2015 |
Irelokeh: Thanks bro but this echoes 6578 I kind off need a 67598 array ok.
$part1 = substr("56876578", 0, -4); //5687 $part2 = substr("56876578", -4); //6758
$array = str_split($part1 ); // [5,6,8,7] $array1 = str_split($part2 ); // [6,7,5,8]
Or
$array = str_split(substr("56876578", 0, -4)); // [5,6,8,7] $array1 = str_split(substr("56876578", -4)); // [6,7,5,8]
|
Programming / Re: Help Construct An Algorithm In Php Code by jacob05(m): 1:24pm On Aug 13, 2015 |
$rest = substr("56876578", 0, -4); //5687 $rest = substr("56876578", -4); //6758
1 Like |
Webmasters / Re: Why PHP Sucks by jacob05(m): 10:13pm On Aug 10, 2015 |
coolsix: hahahaha... Are you kidding me?
Switch to JavaScript? Yes !!!... Node is a very strong, fast, and powerful cross-platform runtime environment for server-side and networking applications using JAVASCRIPT.... While I'm not advising moving websites to us Node, I'd advise using Node to build your NEXT..... Web application.. ![wink](https://www.nairaland.com/faces/wink.png) |
Webmasters / Re: Why PHP Sucks by jacob05(m): 9:52pm On Aug 10, 2015 |
A very nice Topic presented in a very wrong way.
Part of Building Scalable Web Apps Today involves building your app to consume an API. I would recommend building the API with NodeJS(Javascript) over PHP because of the speed and the asynchronous nature.
That aside PHP is really a very good language. Using a Framework like Laravel would help you appreciate , more , the beauty of PHP. 1 Like |
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 7:58pm On Aug 10, 2015 |
RUN
|
Programming / Re: Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD by jacob05(m): 5:36pm On Aug 10, 2015 |
dhtml:
What makes you think your viewers know how to add and subtract in the first place? So how will they even correct you? Anyway, carry go o jare. Lolz.....aba |