Skip to content

Instantly share code, notes, and snippets.

@fdcore
fdcore / pearson_correlation.php
Last active December 29, 2021 20:26
Php simple pearson correlation Function
<?php
function pearson_correlation($x,$y){
if(count($x)!==count($y)){return -1;}
$x=array_values($x);
$y=array_values($y);
$xs=array_sum($x)/count($x);
$ys=array_sum($y)/count($y);
$a=0;$bx=0;$by=0;
for($i=0;$i<count($x);$i++){
@dg
dg / websocket.html
Created August 11, 2013 15:54
WebSocket communication between PHP and single client
<!doctype html>
<script>
if ("WebSocket" in window) {
var ws = new WebSocket("ws://127.0.0.1:31339");
ws.onopen = function() {
console.log('connected');
};
ws.onerror = function(e) {
@talitapagani
talitapagani / navigationTiming-analytics.js
Created May 13, 2014 19:37
How to use Navigation Timing API with Google Analytics
function getPerfStats() {
var timing = window.performance.timing;
return {
dns: timing.domainLookupEnd - timing.domainLookupStart,
connect: timing.connectEnd - timing.connectStart,
ttfb: timing.responseStart - timing.connectEnd,
basePage: timing.responseEnd - timing.responseStart,
frontEnd: timing.loadEventStart - timing.responseEnd
};
}
@tim545
tim545 / zerowidthspace.md
Last active August 11, 2019 14:51
The most evil character in Unicode

'Zero Width Space' character

I had some trouble with this character in a client project, it was hidden inside a configuration string which is validated in the clients API. It's basically invisible, literally a space character with zero width, it could not be seen but it was breaking at the API because it would not validate, causing problems with hundreds of user accounts.

The Unicode value of this character is U+200B, and it's evil, very evil. Lying in wait to break your applications while leaving no sign of it's presence...

It also has some friends, check the answer of this Stack Overflow question

In my project, it was one of my colleuges who managed to find the character, he re-copied the string into the code and Git showed that the line had been changed, even though all the Git GUI's didn't actually show any difference. He ran git diff in the command line and this did show the Unicode character being deleted, that's somet

@rmhrisk
rmhrisk / WebCrypto Support.md
Last active July 12, 2019 07:42
WebCrypto Support as of May 4th 2017

Edge image

Safari image

Chrome image

Firefox

@MichalKalita
MichalKalita / Soupis webů s Nette Framework
Last active November 4, 2018 19:31
Update 29.4.2016: zkontrolováno cca 200 000 stránek, podle hlavičky "X-Powered-By"
http://www.100reklam.cz
http://10hvezd.cz
http://12plus12.cz
http://www.17november1989.sk
http://1bazar.sk
http://www.1cfc.cz
http://1cornhill.com
http://1site.cz
http://www.1weby.cz
http://24keys.cz
String.prototype.hashCode = function() {
var hash = 0, i, chr, len;
if (this.length === 0) return hash;
for (i = 0, len = this.length; i < len; i++) {
chr = this.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
@larchanka
larchanka / hashcode.js
Last active January 12, 2018 14:50
JavaScript: Java String.hashCode() implementation. Source: http://goo.gl/Hyt1ku
String.prototype.hashCode = function() {
var hash = 0;
try {
if (this.length == 0) return hash;
for (i = 0; i < this.length; i++) {
char = this.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
@milo
milo / fid-remove.js
Created April 20, 2017 12:46
Flash message _fid parameter remove.
(function (w, timeout) {
setTimeout(function () {
var url = w.location.toString();
if (w.history && w.history.replaceState && url.indexOf('_fid=') !== -1) {
w.history.replaceState({}, null, /[?&]_fid=[^&]+$/.test(url)
? url.replace(/[?&]_fid=[^&]+/, '')
: url.replace(/([?&])_fid=[^&]+&/, '$1')
);
}
}, timeout || 2000);
@dg
dg / ssl.conf
Created December 14, 2015 21:37
Redirect to HTTPS for all except Windows XP
server {
...
listen 443 ssl;
listen 80;
if ($server_port = 80) {
set $xp A;
}