function findDupes(arr) { for (let i = 0; i < arr.length; i++){ if (hash[arr[i]] === "true"){ dupes.push(arr[i]); } hash[arr[i]] = "true" ; } console.log(dupes); } let arr = [1, 5, 6, 6, 6, 5 ,6 ,7 ,3, 2, 1, 3]; let dupes = []; let hash = {}; findDupes(arr);
HowTo
How to turn off System Integrity Protection in macOS
How to turn off System Integrity Protection in macOS
1. Restart your mac
2. Hold down Command-R to reboot into Recovery Mode
3. Click Utilities
4. In Terminal enter `csrutil disable`
5. Restart
A Retro Adventure Game Creator for Your Favorite Handheld Video Game System
John Gruber via Daring Fireball:
GB Studio is “A free and easy to use retro adventure game creator for your favourite handheld video game system”, by which they mean, but don’t want to name specifically, Nintendo’s GameBoy.
What a fun idea from developer Chris Maltby. You can output ROMs for emulators, play them on actual GameBoy hardware with a flash cartridge, or even export them for the web (which will even work on phones). It’s a remarkably polished IDE.
Get it here.
How to Use iOS GameCenter Leaderboards in Unity3d
You need to setup your app on the appstore connect first with the appropriate leaderboard. And you can only test this code on the iOS device and not in the unity3d player.
using UnityEngine.SocialPlatforms; private ILeaderboard leaderboard; private string leaderboard_id = "yourleaderboardid"; // setup on appstore connect void Start() { // Authenticate user first Social.localUser.Authenticate(success => { if (success) { Debug.Log("Authentication successful"); string userInfo = "Username: " + Social.localUser.userName + "\nUser ID: " + Social.localUser.id + "\nIsUnderage: " + Social.localUser.underage; Debug.Log(userInfo); } else Debug.Log("Authentication failed"); }); // create social leaderboard leaderboard = Social.CreateLeaderboard(); leaderboard.id = leaderboard_id; leaderboard.LoadScores(result => { Debug.Log("Received " + leaderboard.scores.Length + " scores"); foreach (IScore score in leaderboard.scores) Debug.Log(score); }); } void ReportScore(long score, string leaderboardID) { Debug.Log("Reporting score " + score + " on leaderboard " + leaderboardID); Social.ReportScore(score, leaderboardID, success => { Debug.Log(success ? "Reported score successfully" : "Failed to report score"); }); } void OpenLeaderboard() { Social.ShowLeaderboardUI(); }
How to Create Looping Sound with Amazon Alexa Skill App
An example how to play audio with AWS Lambda function for your Amazon Alexa Skill:
The way to do this is to append the same mp3 file to the play queue once the current file is “nearly finished” playing.
const Alexa = require('ask-sdk-core'); const soundURL = 'https://urltosomefile.mp3'; let expectedPreviousToken = ''; const LaunchRequestHandler = { canHandle(handlerInput) { return handlerInput.requestEnvelope.request.type === 'LaunchRequest'; }, handle(handlerInput) { expectedPreviousToken = 'sometoken' + Math.random(); return handlerInput.responseBuilder .speak('start playing sound') .addAudioPlayerPlayDirective('REPLACE_ALL', soundURL, expectedPreviousToken, 0, null) .withSimpleCard('Example', 'Example') .getResponse(); } }; const StartSoundHandler = { canHandle(handlerInput) { return handlerInput.requestEnvelope.request.type === 'IntentRequest' && handlerInput.requestEnvelope.request.intent.name === 'StartSoundHandler'; }, handle(handlerInput) { expectedPreviousToken = 'sometoken'+Math.random(); return handlerInput.responseBuilder .addAudioPlayerPlayDirective ('REPLACE_ALL', soundURL, expectedPreviousToken, 0, null) .withSimpleCard('Example', 'Example') .getResponse(); } }; const ExitHandler = { canHandle(handlerInput) { const request = handlerInput.requestEnvelope.request; return request.type === 'IntentRequest' && (request.intent.name === 'AMAZON.StopIntent' || request.intent.name === 'AMAZON.CancelIntent'); }, handle(handlerInput) { return handlerInput.responseBuilder .addAudioPlayerStopDirective() .getResponse(); } }; const SessionEndedRequestHandler = { canHandle(handlerInput) { return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest'; }, handle(handlerInput) { //any cleanup logic goes here return handlerInput.responseBuilder.getResponse(); } }; const PausePlaybackHandler = { canHandle(handlerInput) { const request = handlerInput.requestEnvelope.request; return request.type === 'IntentRequest' && request.intent.name === 'AMAZON.PauseIntent'; }, handle(handlerInput) { return handlerInput.responseBuilder .speak('Sound is paused.') .addAudioPlayerStopDirective() .withSimpleCard('Example', 'Bye!') .getResponse(); }, }; const AudioPlayerEventHandler = { canHandle(handlerInput) { const request = handlerInput.requestEnvelope.request; return request.type === 'AudioPlayer.PlaybackStarted' || request.type === 'AudioPlayer.PlaybackStopped' || request.type === 'AudioPlayer.PlaybackNearlyFinished' || request.type === 'AudioPlayer.PlaybackFailed'; }, handle(handlerInput) { const request = handlerInput.requestEnvelope.request; switch (request.type) { case 'AudioPlayer.PlaybackStarted': expectedPreviousToken = request.token; return handlerInput.responseBuilder .getResponse(); case 'AudioPlayer.PlaybackFinished': return handlerInput.responseBuilder .getResponse(); case 'AudioPlayer.PlaybackStopped': return handlerInput.responseBuilder .getResponse(); case 'AudioPlayer.PlaybackNearlyFinished': return handlerInput.responseBuilder .addAudioPlayerPlayDirective ('ENQUEUE', soundURL, 'sometoken', 0, expectedPreviousToken) .getResponse(); case 'AudioPlayer.PlaybackFailed': console.log('Playback Failed'); break; } return handlerInput.responseBuilder.getResponse(); }, }; const ErrorHandler = { canHandle() { return true; }, handle(handlerInput, error) { console.log(`Error handled: ${error.message}`); return handlerInput.responseBuilder .getResponse(); } }; exports.handler = Alexa.SkillBuilders.custom() .addRequestHandlers( LaunchRequestHandler, StartSoundHandler, ExitHandler, SessionEndedRequestHandler, PausePlaybackHandler, AudioPlayerEventHandler) .addErrorHandlers(ErrorHandler) .lambda();
How to Enable Preflight CORS in PHP for Angular HTTP requests
When testing Ionic or Angular app you might need to set CORS policy to access a service on a different domain. One way to do this in PHP for testing is to send OK responses for all OPTIONS requests. (If you are testing POST and GET requests)
In your php file set:
// change to your app origin header('Access-Control-Allow-Origin: http://localhost:8100'); header ("Access-Control-Expose-Headers: Content-Length, X-JSON"); header ("Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS"); header ("Access-Control-Allow-Headers: Content-Type, Authorization, Accept, Accept-Language, X-Authorization"); header('Access-Control-Max-Age: 86400'); if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { // The request is using the POST method header("HTTP/1.1 200 OK"); return; }
Don’t ship this test code, this is just for your internal testing of http requests.