I'm fairly new to React native, and i would like to have all my endpoints URLs in the same place
So, i have in my environement.js:
module.exports = {
SERVER: 'http://url.com',
API_VERSION: '/api/v3',
FULL_URL: this.SERVER + this.API_VERSION,
PLAYERS: this.FULL_URL + '/players',
TEAMS: this.FULL_URL + '/teams',
};
And on the other side in getGame.js
GLOBAL = require('../environement');
function getGame() {
console.log(GLOBAL.PLAYERS)
}
When i run my app i got
undefined/players
What am i doing wrong?
Thanks
You can try something like this using ES6.
const SERVER = 'http://url.com';
const API_VERSION = '/api/v3';
export const FULL_URL = SERVER + API_VERSION;
export const PLAYERS = FULL_URL + '/players';
export const TEAMS = FULL_URL + '/teams';
And then
import { FULL_URL, PLAYERS, TEAMS } from 'path/to/the/file'
Please take a look to this solution: https://github.com/luggit/react-native-config .
Also it will be very helpful when you will be have a few different environments and build agent for app in teamcity for example.
Related
I can see the req.sessionID, it's like yeVIo68JZHLb9rvA3Js2MY6RMOo1p29S.
In the browsers console I can see the connect.sid and it looks something like this s%3AEsvCST_KXoCmyD1ixT1Elksp7WQU5Bwp.a1zlev0vJ0dNESbPCeOXZq3jsPAsAGCS7O0KTyrOTAU
I took a look at the cookie-signature library and it's not ithe same as what I see in connect.sid as it has the word "hello" in the signature.
var cookie = require('cookie-signature');
var val = cookie.sign('hello', 'tobiiscool');
val.should.equal('hello.DGDUkGlIkCzPz+C0B064FNgHdEjox7ch8tOBGslZ5QI');
How do I convert req.sessionID to connect.sid?
import * as crypto from 'crypto';
const getConnectSid = (sessionID) => {
return 's.'+sessionID+'.'+crypto.createHmac('sha256', process.env.COOKIE_SECRET) .update(sessionID).digest('base64').replace(/\=+$/, '');
}
I am trying to make my own discord bot using VB.Net and I want to add command what change bot name command is working but name changing don't work and I don't know how to fix it.
my attempt #1
Dim Client As Discord.IDiscordClient
Dim Guild As IGuild = Await Client.GetGuildAsync("256776363892015115")
Dim user = Guild.GetUserAsync(Discord.CurrentUser.Id)
Await user.Result.ModifyAsync(New GuildUserProperties With {
.Nickname = "Kissa"
})
my attempt #2
Discord.GetGuild("256776363892015115").GetUser(Discord.CurrentUser.Id).ModifyAsync(New GuildUserProperties With {
.Nickname = "asd"
})
Images about code:
Do it like this:
Version 0.9:
var user = Discord.GetGuild("256776363892015115").GetUser(Discord.CurrentUser.Id);
await user.Edit(nickname: "MySuperBot");
Version 1.x
var guild = discordClient.GetGuild(256776363892015115);
var user = guild.GetUser(discordClient.CurrentUser.Id);
await user.ModifyAsync(x => {
x.Nickname = "MySuperBot";
});
discord.GetGuild("256776363892015115").GetUser(discord.CurrentUser.Id).ModifyAsync(Function(x)
x.Nickname = "MySuperBot"
End Function)
How come this line works with no errors
var gicon = species[ii].color[0] ? require('../assets/gLight.jpg') : require('../assets/nLight.png');
while this line throws an error?
which_light = "gLight";
var gicon = species[ii].color[0] ? require('../assets/' + which_light + '.jpg') : require('../assets/nLight.png');
Image names are resolved during packaging. There is a section about it in the docs. You can solve your problem by defining constants for the images:
const LIGHT_G = require('../assets/gLight.jpg');
const LIGHT_N = require('../assets/nLight.png');
which_light = LIGHT_G;
var gicon = species[ii].color[0] ? which_light : LIGHT_N;
You have to reference all possible images like this.
I am creating some campaign swf banners and I don't use action script very often so any help from the experts would be great thanks.
I am supplying my banners on my website as resource downloads. And tutorials of how to embed the swf which has some javascript flashvars.
These flash variable is then concatenated into a google campaign link to change the utm_source.
This is my javascript...
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<script type="text/javascript">
var flashvars = {};
flashvars.campaignSource = window.location.hostname;
var params = {};
params.loop = "true";
params.quality = "best";
params.wmode = "opaque";
params.swliveconnect = "true";
params.allowscriptaccess = "always";
var attributes = {};
swfobject.embedSWF("banner.swf", "banner_mpu", "300", "250", "9.0.0", false, flashvars, params, attributes);
</script>
and my html...
<div id="banner_mpu">
<a href="http://www.adobe.com/go/getflashplayer">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
</a>
</div>
So the above js works great, however, not everyone will use my tutorial code and will probably use there own methods to embed the swf banner on their site.
So I need some back up action script 2 to get the current hostname into a action script variable
This is my action script which I have so far on my button (swf)...
on(release) {
function GetTheHostname() {
var RootFullUrl = _root._url;
txtFullUrl.text = RootFullUrl;
var lastSlashIndex:Number = RootFullUrl.lastIndexOf("/");
var DriveIndex:Number = RootFullUrl.indexOf("|");
if (DriveIndex>=0) {
baseUrl = RootFullUrl.substring(0, DriveIndex);
baseUrl += ":";
} else {
baseUrl = "";
}
baseUrl += RootFullUrl.substring(DriveIndex+1, lastSlashIndex+1);
txtBaseUrl.text = baseUrl;
return baseUrl;
}
var campaignSourceAS2:String= GetTheHostname();
if ( _root.campaignSource == undefined ) {
getURL("http://www.mysite.co.uk/?utm_source=" + campaignSourceAS2 + "&utm_medium=MPU&utm_campaign=My%20Campaign%202012", "_blank");
} else {
getURL("http://www.mysite.co.uk/?utm_source=" + _root.campaignSource + "&utm_medium=MPU&utm_campaign=My%20Campaign%202012", "_blank");
}
}
The problem with my action script is that it returns the full current URL.
Can any one please help me adapt the GetTheHostname function to get the host name instead of the baseURL
Thanks in advance
In that case, I guess it would be as easy as stripping the http:// from the url and then get all that's left to the first /
A one-liner to go from 'http://www.example.com/category/actionscript' to 'www.example.com' would be
var baseURL:String = _root._url.split("http://").join("").split("/")[0];
and to replace your full method
getURL("http://www.mysite.co.uk/?utm_source=" + (_root.campaignSource || _root._url.split("http://").join("").split("/")[0]) + "&utm_medium=MPU&utm_campaign=My%20Campaign%202012", "_blank");
Hi i have bookmarklet code to load a scripts from a mirrored backup location if my main hosting goes down, it works but i want to know the best way to do this as i know the current way i am doing it is probably not the best way.
(this is a example of my backup bookmarlet code expanded)
javascript: (function () {
var scriptname = 'testscript';
function checkServerStatus() {
var v = setTimeout(function () {
loadscript('backupserver.hardiman.co.nz')
}, 4500);
var a = document.body.appendChild(document.createElement('img'));
a.onload = function () {
clearTimeout(v);
loadscript('screepts.com')
};
a.src = 'http://screepts.com/ping.gif?' + Math.random();
}
checkServerStatus();
function loadscript(b) {
var a = document.createElement('script');
a.type = 'text/javascript';
a.src = 'http://' + b + '/bm/' + scriptname + '.js?' + Math.random();
document.getElementsByTagName('head')[0].appendChild(a)
}
})();`
And this is it wrapped up as a bookmarklet :
Test Script
Any help or advice on loading a script from a backup server would be greatly appreciated..
Okay sorry i should have been more specific on the question. Since my hosting went down i was able to test the above code properly. I think the only thing i need to do is parse what server was loaded to the script.