Integridade da Global window no JavaScript

Algumas ideias que se costumam usar para o código ser mais seguro (a primeira refere-se ao teu exemplo, e propriedades de window) :

  • regista como imutáveis as propriedades de window

No trabalho fizemos assim:

 const defineConstantProperty = function(key, value){
    Object.defineProperty(window, key, {
        value: value,
        writable: false,
        enumerable: true,
        configurable: false
    });
};

defineConstantProperty('propriedade', {% valor %});

e podes até testar isso no teu exemplo:

const defineConstantProperty = function(key, value, obj) {
  Object.defineProperty(obj || window, key, {
    value: value,
    writable: false,
    enumerable: true,
    configurable: false
  });
};

defineConstantProperty('console', console);
defineConstantProperty('log', console.log, console);

let oldLog = console.log;

console.log = function(message) {
  oldLog('CAPITURA')
  oldLog.apply(console, arguments);
};

console.log('teste')
  • usar IIFEs para evitar variáveis no escopo global (podes ler mais aqui)

  • usar const para evitar que variáveis sejam sobre escritas

  • usar let e const pelas vantagens do seu escopo de bloco

  • nunca confies no que vem do cliente, faz sempre verificação no servidor

  • evita ter informação sensível em URLs ou em variáveis, usa sempre indicadores (ids que podes usar no servidor) em vez da informação sensível

special functions – Are symbols automatically generated when defining a variable in the global context and what are symbols?

Abstract: I have noticed something really tricky with Mathematica and the documentation for symbols is short on clearing the confusion. It likely reveals what symbols are but it’s not very prominent. I know unique symbols are created inside Modules but are they also generated every time we define regular functions and variables?

About The Code: I did a simple test with abc = 123. The output for ?abc gives a grayed out Symbol and SymbolName produces an error message. Does this mean it is not a symbol?

abc = 123
?abc
SymbolName[abc]

Four Questions:

  1. Are system functions symbols?
  2. Are user defined functions symbols?
  3. Are user defined variables symbols?
  4. What are symbols and are they automatically generated?

[ Global Warming ] Open Question : Which one of these songs is ur favorite?

    Smells Like Teen Spirit – Nirvana

    Imagine – John Lennon

    One – U2

    Billie Jean – Michael Jackson

    Bohemian Rhapsody – Queen

    Hey Jude – The Beatles

    Like A Rolling Stone – Bob Dylan

    I Can’t Get No Satisfaction – Rolling Stones

    God Save The Queen – Sex Pistols

    Sweet Child O’Mine – Guns N’ Roses

    London Calling – The Clash

    Waterloo Sunset – The Kinks

    Hotel California – The Eagles

    Your Song – Elton John

    Stairway To Heaven – Led Zeppelin

    The Twist – Chubby Checker

    Live Forever – Oasis

    I Will Always Love You – Whitney Houston

    Life On Mars? – David Bowie

    Heartbreak Hotel – Elvis Presley

    Over The Rainbow – Judy Garland

    What’s Goin’ On – Marvin Gaye

    Born To Run – Bruce Springsteen

    Be My Baby – The Ronettes

    Creep – Radiohead

    Bridge Over Troubled Water – Simon & Garfunkel

    Respect – Aretha Franklin

    Family Affair – Sly And The Family Stone

    Dancing Queen – ABBA

    Good Vibrations – The Beach Boys

    Purple Haze – Jimi Hendrix

    Yesterday – The Beatles

    Jonny B Good – Chuck Berry

    No Woman No Cry – Bob Marley

    Hallelujah – Jeff Buckley

    Every Breath You Take – The Police

    A Day In The Life – The Beatles

    Stand By Me – Ben E King

    Papa’s Got A Brand New Bag – James Brown

    Gimme Shelter – The Rolling Stones

    What’d I Say – Ray Charles

    Sultans Of Swing – Dire Straits

    God Only Knows – The Beach Boys

    You’ve Lost That Lovin’ Feeling – The Righteous Brothers

    My Generation – The Who

    Dancing In The Street – Martha Reeves and the Vandellas

    When Doves Cry – Prince

    A Change Is Gonna Come – Sam Cooke

    River Deep Mountain High – Ike and Tina Turner

    Best Of My Love – The Emotions

AMATI Global – amatiglobal.london – HYIPs

Start 2020-05-20. PerfectMoney, 0 Trust Score point(s) (United Kingdom GB.GIF), Payeer, Bitcoin, Litecoin 

Languages: EN 

8769.jpg 

Description: 

Amati Global Investors is a specialist fund management business based in Edinburgh. It focuses on UK small and mid-sized companies, with a universe ranging from fully listed constituents of the FTSE Mid 250 and FTSE Small Cap indices, to stocks quoted on the Alternative Investment Market (“AIM”). Products include an OEIC – the TB Amati UK Smaller Companies Fund; an AIM Venture Capital Trust – Amati AIM VCT; and an AIM IHT portfolio service.

 

Investment plans: 


 4.26-4.97% Hourly for 24 Hours


Plan    Spent Amount ($)    Hourly Profit (%)


Plan 1    $10.00 – $100.00    4.26


Plan 2    $101.00 – $1000.00    4.52


Plan 3    $1001.00 – $5000.00    4.64


Plan 4    $5001.00 – $9999.00    4.97


 5.26-5.97% Hourly for 24 Hours


Plan    Spent Amount ($)    Hourly Profit (%)


Plan 1    $200.00 – $500.00    5.26


Plan 2    $501.00 – $10000.00    5.35


Plan 3    $10001.00 – $49999.00    5.97


 6.26-6.97% Hourly for 24 Hours


Plan    Spent Amount ($)    Hourly Profit (%)


Plan 1    $300.00 – $1000.00    6.26


Plan 2    $1001.00 – $50000.00    6.46


Plan 3    $50001.00 – $99999.00    6.97


 

Our deposit: 

22.05.20 12:22     Transfer     Sent Payment: 60.00 USD to account U24809789 from U1294xxx. Batch: 315644935. Memo: Shopping Cart Payment. Deposit to AMATI Global User allhyips.

Details: 

Minimal deposit: $10
Maximal deposit: $99999
Referral comission: 10%
Payments: Instant 
Features: SSL,DDOS

Whois:

Registrar    NameCheap, Inc. 

Dates    4 days old
Created on 2020-05-18
Expires on 2021-05-18
Updated on 2020-05-18     
 
Name Servers    
DNS1.NAMECHEAPHOSTING.COM. (has 835,417 domains)
DNS2.NAMECHEAPHOSTING.COM. (has 835,417 domains)

SIGN UP 

angular – HttpInterceptor not calling Global Error Handler

I am performing a spike to investigate the global error handler within Angular, I am trying to simulate client side and server side errors but when I force a http error(fake end point) the errors seem to get outputted to the console instead of getting dealt with the error handler, meaning they don’t even call through to the error handler.

ErrorHandler

@Injectable({
  providedIn: 'root'
})
export class GlobalErrorHandler implements ErrorHandler {

  constructor(private injector: Injector) { }

    handleError(error: Error | HttpErrorResponse): void {
      const errorService = this.injector.get(ErrorService);
      const notifier = this.injector.get(NotificationService);

      let message;
      let stackTrace;
      if(error instanceof HttpErrorResponse){
          //Server error
          message = errorService.getServerMessage(error);
          stackTrace = errorService.getServerStack(error);
      }else{
          //Client Error
          message = errorService.getClientMessage(error);
          stackTrace = errorService.getClientStack(error);
      }
      notifier.showError(message);
    }
}

Interceptor

export class ServerErrorInterceptorService implements HttpInterceptor {

  constructor() { }

    intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        return next.handle(req).pipe(
            catchError((error: HttpErrorResponse) => {
                if (error.error instanceof ErrorEvent) {
                    // client-side error or network error

                } else {
                    // TODO: Clean up following by introducing method
                    if (error.status === 498) {
                        // TODO: Destroy local session; redirect to /login
                    }
                    if (error.status === 401) {
                        // TODO: Permission denied; show toast
                    }
                }
                return throwError(error);
            })
        )
    }
}

Module provider:

providers: (
    { provide: ErrorHandler, useClass: GlobalErrorHandler },
    { provide: HTTP_INTERCEPTORS, useClass: ServerErrorInterceptorService, multi: true}
)

and component:

    export class ErrorHandlingComponent implements OnInit {

  constructor(private httpClient: HttpClient) { }

  numberArray: number();

  ngOnInit() {
  }

  causeError(){
       this.numberArray(-1) = 1;
  }

    causeServerSideError() {
        this.httpClient.get("STUB URL").subscribe((x: number()) => this.numberArray = x)
    }
}

Why does NMaximize miss this global maximum?

I am having trouble maximizing a function which appears as a curvature of a planar curve.

{tmin, tmax} = {0, 2 Pi}

f = -((6-3 Cos(t) - Cos(3 t))/((-11+6 Cos(t) + 8 Cos(2 t) - 6 Cos(3 t) + Cos(4 t))
  Sqrt(Cos(t)^2 + 9 Sin(t)^2 - 12 Cos(t) Sin(t)^2 + 4 Cos(t)^2 Sin(t)^2)));

NMaximize({f, tmin <= t <= tmax}, t)

says that the maximum of $f$ is attained at

{1.37888, {t -> 5.78352}}

But,

Plot(f, {t, tmin, tmax}, PlotRange -> Full)

plot of f

indicates that the true maximum is attained at $t=pi$.

Why is this happening?
I’m using Mathematica version 12.0.0 for Microsoft Windows (64-bit).

javascript – Change one SharePoint site link in the Global Navigation redirect to another site for all users except one

For example, a site in the global navigation, when clicked should redirect to another site for all users except one. Also, users who have saved the site as bookmarks should be redirected too when they open the link. How does the .js file look like and where should I add it? Any help appreciated.

How to edit a global type in TypeScript?

window.getComputedStyle returns a value with type CSSStyleDeclaration, which has CSS properties keys in camelcase format.

However, tested both on Chrome, Firefox, and Safari, it returns the keys’ values in both camelcase, and hyphen separated format, and I reference the keys with hyphen separated format:

const div = document.querySelector('div#test');
const computedStyles = window.getComputedStyle(div);

console.log(
  'marginTop:', computedStyles.marginTop,
  'margin-top:', computedStyles('margin-top')
);
div#test {
  width: 100px;
  height: 100px;
  background-color: aqua;
  margin-top: 50px;
}
<div id='test'></div>

It causes me a need to use a lot of ugly as unknown as ..., so I’ve decided to add extra properties to CSSStyleDeclaration. I’m just not sure how to do it.

Amati Global – Amatiglobal.london

Start 2020-05-20. PerfectMoney, 0 Trust Score point(s) (United Kingdom IPB Image), Payeer, Bitcoin, Litecoin

Languages: EN

IPB Image

Description:

QUOTE

Amati Global Investors is a specialist fund management business based in Edinburgh. It focuses on UK small and mid-sized companies, with a universe ranging from fully listed constituents of the FTSE Mid 250 and FTSE Small Cap indices, to stocks quoted on the Alternative Investment Market (“AIM”). Products include an OEIC – the TB Amati UK Smaller Companies Fund; an AIM Venture Capital Trust – Amati AIM VCT; and an AIM IHT portfolio service.

Investment plans:

4.26-4.97% Hourly for 24 Hours
Plan Spent Amount ($) Hourly Profit (%)
Plan 1 $10.00 – $100.00 4.26
Plan 2 $101.00 – $1000.00 4.52
Plan 3 $1001.00 – $5000.00 4.64
Plan 4 $5001.00 – $9999.00 4.97

5.26-5.97% Hourly for 24 Hours
Plan Spent Amount ($) Hourly Profit (%)
Plan 1 $200.00 – $500.00 5.26
Plan 2 $501.00 – $10000.00 5.35
Plan 3 $10001.00 – $49999.00 5.97

6.26-6.97% Hourly for 24 Hours
Plan Spent Amount ($) Hourly Profit (%)
Plan 1 $300.00 – $1000.00 6.26
Plan 2 $1001.00 – $50000.00 6.46
Plan 3 $50001.00 – $99999.00 6.97

Our deposit:

22.05.20 12:22 Transfer Sent Payment: 60.00 USD to account U24809789 from U1294xxx. Batch: 315644935. Memo: Shopping Cart Payment. Deposit to AMATI Global User allhyips.

Details:

Minimal deposit: $10
Maximal deposit: $99999
Referral comission: 10%
Payments: Instant
Features: SSL,DDOS

Whois:

Registrar NameCheap, Inc.

Dates 4 days old
Created on 2020-05-18
Expires on 2021-05-18
Updated on 2020-05-18

Name Servers
DNS1.NAMECHEAPHOSTING.COM. (has 835,417 domains)
DNS2.NAMECHEAPHOSTING.COM. (has 835,417 domains)

SIGN UP