Skip to content

Instantly share code, notes, and snippets.

View jeystaats's full-sized avatar
🏠
Working from home

Jasper Staats jeystaats

🏠
Working from home
View GitHub Profile
@jeystaats
jeystaats / sendSlackPartyGiphy.php
Last active January 13, 2021 23:19
Sends a party gif to your Slack Channel!
<?php
public function _sendSlack($data)
{
$webhook = 'INSERT WEBHOOK TOKEN HERE';
// get celebrate gif
// http://api.giphy.com/v1/gifs/random?api_key=KEY&tag=party&limit=1
$curl = curl_init();
curl_setopt_array($curl, array(
@jeystaats
jeystaats / intoRgb.js
Created February 24, 2017 09:15
Turn a string ( username e.g ) into a RGB ( 15e5de ) . Only put the hashtag in front of it.
// Turn a string ( like a username , into a RGB code (15e5de) , you can use this for styling purposes per user in chat examples
hashCode(str) { // java String#hashCode
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
return hash;
},
intToRGB(i){
var c = (i & 0x00FFFFFF)
toHHMMSS(sec) {
let sec_num = parseInt(sec, 10); // don't forget the second parm
let hours = Math.floor(sec_num / 3600);
let minutes = Math.floor((sec_num - (hours * 3600)) / 60);
let seconds = sec_num - (hours * 3600) - (minutes * 60);
let Ohours = hours + '';
let Ominutes = minutes + '';
let Oseconds = seconds + '';
if (hours < 10) {
@jeystaats
jeystaats / setActive.php
Created February 25, 2017 11:24
Return active string if a route is active
<?php
function set_active($path) {
if (strpos(\Request::route()->getName(), $path) !== false) {
return 'active';
}
}
<?php
function HHMMSStoSeconds($time) {
return strtotime("1970-01-01 $time UTC");
}
function secondsToHHMMSS($seconds) {
return sprintf("%02d%s%02d%s%02d", floor($seconds / 3600), ':', ($seconds / 60) % 60, ':', $seconds % 60);
}
public toSeconds(time) {
var parts = time.split(':');
return (+parts[0]) * 60 * 60 + (+parts[1]) * 60 + (+parts[2]);
}
@jeystaats
jeystaats / DiffCollection.php
Last active February 25, 2017 11:34
Difference in Collection ( Laravel )
<?php
$array1 = ['Rocket','Thruster','Space'];
$array2 = ['Rocket','Rocks','Space'];
$collection = collect($array1);
$intersect = $collection->intersect($array2);
var_dump($intersect )
// $intersect = ['Rocket','Space'];
@jeystaats
jeystaats / functionality.php
Last active February 25, 2017 12:06
Laravel send slack notification
<?php
$this->notification('Nieuw bericht', 'Er is een nieuw bericht :ghost:', config('slack.color'),
[
'title' => "Veld 1",
'value' => 'Dingen',
'short' => true,
], [
'title' => "Veld 2",
'value' => 'Nog meer dingen',
@jeystaats
jeystaats / valet-fetch.sh
Created July 19, 2017 20:07
Valet URL to .env file automatically
#!/bin/bash
export var=`valet fetch-share-url`
sed -i -e "s@.*APP_URL.*@APP_URL=$var@" $result
echo "💪 - Valet share URL has been replaced 📋 "
@jeystaats
jeystaats / stresstest.js
Created June 11, 2018 15:40
XHR Stresstest
var change = 0;
var simultanius = 0;
var que = 1000; // number of tests
Array(que).join(0).split(0).forEach(function(a,i){
var xhr = new XMLHttpRequest;
xhr.open("GET",'/?' + i); // cacheBust
xhr.onreadystatechange = function() {
if(xhr.readyState == 2){