Best way to Spell Check a web page [closed] - web

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
When adding text to a webpage best practice would be to use localization resources, or at least copy/paste text out of a program like Word (or any other grammar/spell checker). That being said there are "always" a couple words here and there where a developer just "updates it."
My question, how do other people check for typos on their webpages? I have a solution (Which I will post as a possible answer), but looking for other ideas.

You can add a function in your javascript library to grab all text and put it in a textbox, which on a browser like chrome will then trigger the native spellchecker.
function SpellCheck()
{
var ta=document.createElement('textarea');
var s=document.createAttribute('style');
s.nodeValue='width:100%;height:100em;';
ta.setAttributeNode(s);
ta.appendChild(document.createTextNode(document.body.innerText));
document.body.appendChild(ta);
ta.focus();
for (var i = 1; i <= ta.value.length; i++)
ta.setSelectionRange(i, i);
}
Code from #JohnLBevan blog post (posted on 2011/03/28)

I made the comment above, then I used the idea from the first answer to add this to my dev environment:
function showPageSource()
{
var text = document.body.innerText;
var textarea = document.createElement('TEXTAREA');
textarea.style.position = 'absolute';
textarea.style.opacity = 0.95;
textarea.style.zIndex = 999;
textarea.style.top = '25px';
textarea.style.left = '25px';
textarea.style.width = 'calc(100% - 50px)';
textarea.style.height = '500px';
textarea.value = text;
document.body.appendChild(textarea);
textarea.addEventListener('click', function (e)
{
e.stopPropagation();
}, false);
document.body.addEventListener('click', function (e)
{
textarea.parentNode.removeChild(textarea);
}, false);
}
And then a tag like this to show the sauce:
SHOW PAGE SOURCE
Shows a fair amount of crap from the navigation - but I can live with that.

Related

Azure search schema migrations [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
What's the best way to migrate an Azure search schema in a release pipeline?
In the SQL world, I'd use something like DbUp. Is there anything similar for Azure search?
Or is there a different approach when the schema needs to change?
It depends on whether you are pushing content via the SDK or if you are pulling content from a supported content source using one of the pre-built indexers. Using the SDK you can add new properties to your model as explained in this post: Update Azure search document schema
Note: Changes in your data model may require either an update or a rebuild of the index. For example, adding new properties only requires and update. But, if you change a setting like searchable, filterable or sortable you will need a rebuild. For details, see How to rebuild an index in Azure Cognitive Search
COMPATIBILITY PROBING VIA PUSH
My preferred solution is to use push indexing for everything. To test if the data model in the index is compatible, I create a sample item and submit to the index. If the model used in the index is incompatible, and error is thrown by the Azure Search SDK. I then delete the index and create it from scratch using my new model.
Here is a simplified method to test if any item is compatible with a named index:
public async Task<bool> TestItemAsync<T>(T item, string indexName)
{
var isCompatible = false;
var indexClient = _searchServiceClient.Indexes.GetClient(indexName);
var indexActions = new List<IndexAction<T>> { IndexAction.MergeOrUpload((item)) };
var batch = IndexBatch.New(indexActions);
try
{
var unused = await indexClient.Documents.IndexAsync(batch);
isCompatible = true;
}
catch
{
// ignored
}
return isCompatible;
}
And here is an example of how you might use it to probe your index for compatibility.
var item = new Product();
item.ID = 123;
item.Title = "Sample";
item.MyNewProperty = "Some value"
// ...
var isCompatible = await TestItemAsync(item, indexName);
if (isCompatible)
{
await DeleteItemAsync(item, indexName);
}
else
{
await DeleteIndexAsync<T>(indexName);
await CreateIndexAsync<T>(indexName);
}
To actually verify the compatiblity, make sure you populate your item with some values. In this example I hard-coded some values for the sake of the example. In actual use I use a Mock framework that populates every property of my item with some random sample value, but I did not want to give the impression that a third-party component is required for this use-case.

json find object by name and grab its value (api) [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
i am grabbing the steam data and saving it to variable called body
now what i want to do is find total_kills its not necessary that this object is always at body.playerstats.stats[0].value so is there any way to find the body by total_kills and get its value
the complete api reply is given below with beautified form
https://codebeautify.org/jsonviewer/cb2b563d
It seems like body.playerstats.stats is an Array that contains objects. What you could do is go through that array and store all the objects that have name: 'total_kills', something like this could work:
const totalKillsArr = body.playerstats.stats.filter((stat) => {
return stat.name === 'total_kills';
});
Once you have the new array of totalKills you can use reduce to get the sum of all total kills:
const sumTotalKills = totalKills.reduce((sum, el) => {
sum += el.value;
return sum;
}, 0);
If there is only one object in the stats array that has the name of total_kills then just use a simple find function on the main array like this:
const totalKills = body.playerstats.stats.find(stat => {
return stat.name === 'total_kills';
});
This will find you the first object with name property of total_kills. If there is no such object it will return undefined.

Moving objects collision Phaser [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
My collision of moving objects is not working. I have created a demo so you can see it and see my problem all code and everything included.
As you may be able to see, I have 2 blocks coming from left to right and then I have a tank shooting bullets> I tried in all kind of directions and I always get the same results, basically my collision only works the velocity of the blocks value, in the example on the zip file only works up to 300px. Depending on the blocks speed, if I change the block speed to a greater number then the collision works on the same numbers pixels. it is really weird.
I was wondering if I'm just doing the whole thing wrong or what could my problem be? I would appreciate any pointers or ideas that can help me solve this issue. Thanks.
Demo source code.
BasicGame.Game = function (game) {
// When a State is added to Phaser it automatically has the following properties set on it, even if they already exist:
this.game; // a reference to the currently running game (Phaser.Game)
this.add; // used to add sprites, text, groups, etc (Phaser.GameObjectFactory)
this.camera; // a reference to the game camera (Phaser.Camera)
this.cache; // the game cache (Phaser.Cache)
this.input; // the global input manager. You can access this.input.keyboard, this.input.mouse, as well from it. (Phaser.Input)
this.load; // for preloading assets (Phaser.Loader)
this.math; // lots of useful common math operations (Phaser.Math)
this.sound; // the sound manager - add a sound, play one, set-up markers, etc (Phaser.SoundManager)
this.stage; // the game stage (Phaser.Stage)
this.time; // the clock (Phaser.Time)
this.tweens; // the tween manager (Phaser.TweenManager)
this.state; // the state manager (Phaser.StateManager)
this.world; // the game world (Phaser.World)
this.particles; // the particle manager (Phaser.Particles)
this.physics; // the physics manager (Phaser.Physics)
this.rnd; // the repeatable random number generator (Phaser.RandomDataGenerator)
// You can use any of these from any function within this State.
// But do consider them as being 'reserved words', i.e. don't create a property for your own game called "world" or you'll over-write the world reference.
this.bulletTimer = 0;
};
BasicGame.Game.prototype = {
create: function () {
//Enable physics
// Set the physics system
this.game.physics.startSystem(Phaser.Physics.ARCADE);
//End of physics
// Honestly, just about anything could go here. It's YOUR game after all. Eat your heart out!
this.createBullets();
this.createTanque();
this.timerBloques = this.time.events.loop(1500, this.createOnebloque, this);
},
update: function () {
if(this.game.input.activePointer.isDown){
this.fireBullet();
}
this.game.physics.arcade.overlap(this.bullets, this.bloque, this.collisionBulletBloque, null, this);
},
createBullets: function() {
this.bullets = this.game.add.group();
this.bullets.enableBody = true;
this.bullets.physicsBodyType = Phaser.Physics.ARCADE;
this.bullets.createMultiple(100, 'bulletSprite');
this.bullets.setAll('anchor.x', 0.5);
this.bullets.setAll('anchor.y', 1);
this.bullets.setAll('outOfBoundsKill', true);
this.bullets.setAll('checkWorldBounds', true);
},
fireBullet: function(){
if (this.bulletTimer < this.game.time.time) {
this.bulletTimer = this.game.time.time + 1400;
this.bullet = this.bullets.getFirstExists(false);
if (this.bullet) {
this.bullet.reset(this.tanque.x, this.tanque.y - 20);
this.game.physics.arcade.enable(this.bullet);
this.bullet.enableBody = true;
this.bullet.body.velocity.y = -800;
}
}
},
createOnebloque: function(){
this.bloquecs = ["bloqueSprite","bloquelSprite"];
this.bloquesr = this.bloquecs[Math.floor(Math.random()*2)];
this.bloque = this.add.sprite(0, 360, this.bloquesr);
this.game.physics.arcade.enable(this.bloque);
this.bloque.enableBody = true;
this.bloque.body.velocity.x = 300;
this.bloque.body.kinematic = true;
this.bloque.checkWorldBounds = true;
this.bloque.outOfBoundsKill = true;
this.bloque.body.immovable = true;
},
createTanque: function() {
this.tanqueBounds = new Phaser.Rectangle(0, 600, 1024, 150);
this.tanque = this.add.sprite(500, 700, 'tanqueSprite');
this.tanque.inputEnabled = true;
this.tanque.input.enableDrag(true);
this.tanque.anchor.setTo(0.5,0.5);
this.tanque.input.boundsRect = this.tanqueBounds;
},
collisionBulletBloque: function(bullet, bloque) {
this.bullet.kill();
},
quitGame: function (pointer) {
// Here you should destroy anything you no longer need.
// Stop music, delete sprites, purge caches, free resources, all that good stuff.
// Then let's go back to the main menu.
this.state.start('MainMenu');
}
};
The code definitely helps, but you can actually get an idea of what's happening just from playing the game.
As the blocks are going by you can actually get the bullets to disappear if you fire and hit the right edge of the center-most block.
What's happening is that you're checking for a collision between the bullets and a block, but the block is getting redefined every time you add a new one to the screen on the left.
What you probably want to do is create a pool of blocks (bloquePool for example), almost exactly like what you're doing in createBullets with your bullet pool (what you've called bullets).
Then check for a collision between the group of bullets and the group of blocks.
this.game.physics.arcade.overlap(
this.bullets, this.bloquePool, this.collisionBulletBloque, null, this
);
You should get the individual bullet and the individual block that collided passed into collisionBulletBloque so you can still kill the bullet as you are.

What is the " Run <extension> command" in the omnibox? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have created an extension that integrates with the omnibox. When I have typed in the keyword + space and then the phrase to send to the extension, I can see that the top row in the omnibox says "Run my-extenison-name command:"
What exactly is this? Can I use this somehow to maybe call methods in my extension?
It would be really nice if it was possible, but I can't find any info on this.
"Run <your-extension-name> command" is simply the "Default" default suggestion for your extension's omnibox. It's basically the placeholder for what is currently entered, and should indicate what will happen if the user presses enter at that point ("search my site for 'x'"). To change it, just add this to your background page
chrome.omnibox.setDefaultSuggestion({"description" : "your description here"});
You can use "%s" in there as well as a placeholder for what the user is typing in.
Jason was right in how you can use onInputEntered to react to the user entering something into the omnibox.
When the user selects the command, any listeners you've added to the onInputEntered event will be fired.
See: http://code.google.com/chrome/extensions/omnibox.html#event-onInputEntered
So yes, you can have Omnibox commands call methods in your extension, just by adding a listener to that event, like so:
chrome.omnibox.onInputEntered.addListener(function(text) {
console.log('User entered command: ' + text);
};
You can also get notifications of the user's omnibox activity while they're typing, or if they cancel typing, by adding listeners for the other events listed on the page linked above.
I do this for my Chrome extension Lil’ Launch which has no use for the default suggestion (it only searches your bookmarks).
The full source is on Github, but the general idea is this. The callback for chrome.omnibox.onInputEntered gets passed either the content property of your selection or the value of the user input if the suggestion is the default one. So I append a known string to the front of all the content properties and check for that same string when chrome.omnibox.onInputEntered fires. It needs to be something that the use is unlikely to type, otherwise the matching will break.
var resultsList = [], // Accessible from the callback scope
unlikely = "GOSHDARNYOUCHROME"; // Our unlikely to be typed String
chrome.omnibox.onInputChanged.addListener(
function(text, suggest) {
var searchResults = chrome.bookmarks.search(text, function(searchResults) {
resultsList = [];
for (var i = 0; i < searchResults.length; i++) {
resultsList.push({
content: unlikely + item.url, // Prepend our unlikely string to the URL
description: "bar"
});
};
// Chrome adds a completely useless default suggestion in our case
// So set the default and slice it off the suggestions
chrome.omnibox.setDefaultSuggestion({ description: resultsList[0].description });
suggest(resultsList.slice(1, -1));
})
}
);
chrome.omnibox.onInputEntered.addListener(
function(text) {
// If text doesn't have unlikely prepended its the stupid default
if(text.substring(0, unlikely.length) !== unlikely) {
text = resultsList[0].content;
}
text = text.substring(unlikely.length); // Trim the unlikely string
// Do something with text
}
);
Stupid, but effective.

How to determine if a file exists in a SharePoint SPFolder [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Is there a way other than looping through the Files in a SPFolder to determine if a give filename (string) exists?
You can, if you know the URL also use the SPFile.Exists property as follows:
using (SPSite site = new SPSite("http://server/site"))
using (SPWeb web = site.OpenWeb())
{
SPFile file = web.GetFile("/site/doclib/folder/filename.ext");
if (file.Exists)
{
...
}
}
One would on first thought assume SPWeb.GetFile throws an exception if the file does not exist. But as you see this is not the case - it will actually return a SPFile object.
But if you are using SP 2010 Client OM, it would actually throw an exception if the file doesn't exist:
using(var clientContext = new ClientContext(site))
{
Web web = clientContext.Web;
Microsoft.SharePoint.Client.File file = web.GetFileByServerRelativeUrl("/site/doclib/folder/filename.ext");
bool bExists = false;
try
{
clientContext.Load(file);
clientContext.ExecuteQuery(); //Raises exception if the file doesn't exist
bExists = file.Exists; //may not be needed - here for good measure
}
catch{ }
if (bExists )
{
.
.
}
}
Using a CAML query is the most efficient way (example here)
CAML can be a bit unwieldy, so also worth looking at the Linq to Sharepoint provider, which hides the details of CAML away from you.

Resources