Skip to content

Instantly share code, notes, and snippets.

View piyyushhpatel's full-sized avatar

PIYYUSHH PATEL piyyushhpatel

View GitHub Profile
@piyyushhpatel
piyyushhpatel / main.go
Created October 20, 2021 12:09 — forked from julz/main.go
containersched minicontainer
package main
import (
"fmt"
"os"
"os/exec"
"syscall"
)
func main() {
@piyyushhpatel
piyyushhpatel / aescmd.go
Created February 11, 2021 10:14 — forked from josephspurrier/aescmd.go
Golang - Encrypt, Decrypt, File Read, File Write, Readline
package main
import (
"bufio"
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"fmt"
"io"
"io/ioutil"

Set the base image to Ubuntu must be first instruction - use docker search to find images

FROM ubuntu # <image>
FROM ubuntu:latest # - <image>:<tag>
FROM ubuntu:precise (LTS)

Set the maintainer info

@piyyushhpatel
piyyushhpatel / converts-webfont-to-base64.js
Created August 28, 2020 06:07 — forked from arielsalminen/converts-webfont-to-base64.js
Convert Google WOFF font to base64 format and inline to <head> of document
// Get binary file using XMLHttpRequest
function getBinary(file) {
var xhr = new XMLHttpRequest();
xhr.open("GET", file, false);
xhr.overrideMimeType("text/plain; charset=x-user-defined");
xhr.send(null);
return xhr.responseText;
}
// Base64 encode binary string
@piyyushhpatel
piyyushhpatel / dateHelpers.js
Last active June 17, 2021 10:53
Date helper functions
/*
To convert mins into hrs
*/
let minToHm = (m) => {
let h = Math.floor(m / 60);
h += (h < 0) ? 1 : 0;
let m2 = Math.abs(m % 60);
m2 = (m2 < 10) ? '0' + m2 : m2;
return (h < 0 ? '' : '+') + h + ':' + m2;
@piyyushhpatel
piyyushhpatel / slatejsCodeExamples.js
Last active May 29, 2020 11:52
Slate js code snipppets
// To get path by slate element
const path = ReactEditor.findPath(editor, props.element)
// search node at path example
export const getNodeAtPath = (editor: any, path: any) => {
const [node] = Editor.node(editor, path);
return node;
};
export const getImage = (editor: any, path: any, id: any): any => {
@piyyushhpatel
piyyushhpatel / httpStatusCodes
Created January 8, 2020 12:56
Http status codes
Set response status via numeric code:
100 "continue"
101 "switching protocols"
102 "processing"
200 "ok"
201 "created"
202 "accepted"
203 "non-authoritative information"
204 "no content"
@piyyushhpatel
piyyushhpatel / XIRR.js
Created August 12, 2019 10:58 — forked from ghalimi/XIRR.js
XIRR Function
// Copyright (c) 2012 Sutoiku, Inc. (MIT License)
// Some algorithms have been ported from Apache OpenOffice:
/**************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
@piyyushhpatel
piyyushhpatel / Avatar.js
Created January 28, 2019 05:45
React Components
import React from "react";
// Default contatiner style
const defStyle = {
width: "60px",
height: "60px",
border: "1px solid",
borderColor: "#eee",
borderRadius: "50%",
backgroundColor: "red",
@piyyushhpatel
piyyushhpatel / numbers.js
Last active October 21, 2020 16:11
Misc
// Rounding Decimals in JavaScript
/*
Rounding Errors
The most common solutions for rounding to a decimal place is to either use Number.prototype.toFixed(), or multiply the float by some power of 10 in order to leverage Math.round(). Both of these work, except sometimes a decimal of 5 is rounded down instead of up.
*/
// First Methods