Skip to content

Instantly share code, notes, and snippets.

@m5r
m5r / xhr.js
Created October 28, 2016 20:29
ES6 XHR from Mackan from Devcord Discord
function loadData(url){
return new Promise((resolve, reject) => {
let xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState === XMLHttpRequest.DONE){
if(xmlhttp.status === 200){
resolve(xmlhttp.responseText);
}else{
reject(xmlhttp.status);
}
@m5r
m5r / keybase.md
Last active August 3, 2018 23:21

Keybase proof

I hereby claim:

  • I am m5r on github.
  • I am mokhtar (https://keybase.io/mokhtar) on keybase.
  • I have a public key whose fingerprint is BED9 087A 5805 6E8B 0B7D 4F94 FE60 7C32 6598 010A

To claim this, I am signing this object:

#!/usr/bin/env bash
set -e # Exit on errors
# A configurable, strict IPTables firewall
# Save this to /usr/local/bin and modify to your needs
# Config - edit this!
ETH_INTERFACE="eth0"
ALLOW_PORTS="22 80 443"
@m5r
m5r / README.md
Created April 9, 2017 17:55 — forked from Dr-Nikson/README.md
Auth example (react + redux + react-router)
@m5r
m5r / color-conversion-algorithms.js
Created October 21, 2017 23:50 — forked from mjackson/color-conversion-algorithms.js
RGB, HSV, and HSL color conversion algorithms in JavaScript
/**
* Converts an RGB color value to HSL. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* Assumes r, g, and b are contained in the set [0, 255] and
* returns h, s, and l in the set [0, 1].
*
* @param Number r The red color value
* @param Number g The green color value
* @param Number b The blue color value
* @return Array The HSL representation
#!/bin/bash
if [ -z "$1" ]; then
echo "Error: No argument passed" >&2; exit 1
fi
if ! [[ $1 =~ ^[0-9]+$ ]] ; then
echo "Error: Argument is not a number" >&2; exit 1
fi
PIDToKill=$(lsof -i:$1 | grep LISTEN | awk '{print $2}' | uniq)
export function serializeServerDataToJsonString(data: Object): string {
const jsonString = JSON.stringify(data);
return jsonString
.replace(/<\/script/gim, '</_escaped_script')
.replace(new RegExp('\u2028', 'g'), '\\u2028')
.replace(new RegExp('\u2029', 'g'), '\\u2029')
.replace(/\\/g, '\\\\')
.replace(/\n/g, '\\n')
.replace(/\r/g, '\\r')
declare global {
interface Window { Paddle: any; }
}
const VENDOR_ID = 111;
const PRODUCT_ID = 222;
type BuyParams = {
coupon?: string | null;
meta?: Record<string, string>;
@m5r
m5r / magic.ts
Last active October 14, 2021 20:08
Magic login link generation and verification
import jwt from "jsonwebtoken";
import { User } from "./entities/user";
export function generateSignInUrl(user: User) {
const token = generateSignInToken(user);
return `${process.env.APP_URL}/auth/verify?token=${token}`;
}
import type { FunctionComponent } from "react";
export const combineProviders = (providers: FunctionComponent[]) => providers.reduce(
(Combined, Provider) => ({ children }) => (
<Combined>
<Provider>{children}</Provider>
</Combined>
),
);