Skip to content

Instantly share code, notes, and snippets.

View prakashsvmx's full-sized avatar

Prakash Senthil Vel prakashsvmx

View GitHub Profile
String.prototype.chunkBy = function(len) {
var current = len;
var previous = 0;
var stack = [];
while (this[current]) {
if (this[current++].match(/s+/)) {
stack.push(this.substring(previous, current));
previous = current;
current += len;
@julianburr
julianburr / context.js
Last active August 27, 2019 09:45
Why Suspense Will Be a Game Changer - Context
const DataContext = React.createContext();
class DataContextProvider extends Component {
// We want to be able to store multiple sources in the provider,
// so we store an object with unique keys for each data set +
// loading state
state = {
data: {},
fetch: this.fetch.bind(this)
};
@julianburr
julianburr / suspense-boundaries.js
Last active August 27, 2019 09:48
Why Suspense Will Be a Game Changer - Suspense Boundaries
class App extends Component {
render () {
return (
<Suspense fallback={<p>Loading...</p>}>
<DeepNesting>
<ThereMightBeSeveralAsyncComponentsHere />
</DeepNesting>
</Suspense>
);
}
@leocristofani
leocristofani / RFReactSelect.js
Last active June 8, 2020 14:59
How to integrate React Select with Redux Form
import React, { PropTypes } from 'react';
import Select from 'react-select';
import 'react-select/dist/react-select.css';
RFReactSelect.defaultProps = {
multi: false,
className: ""
};
RFReactSelect.propTypes = {
@hyber1z0r
hyber1z0r / useWhenVisible.ts
Created August 4, 2020 09:47
useWhenVisible hook
import React, { useEffect } from 'react';
const useWhenVisible = (target: Element | undefined,
callback: () => void,
root: Element | undefined = document.body) => {
useEffect(() => {
if (!target || !root) {
return;
}
@kerneltime
kerneltime / minio.tls.md
Last active February 18, 2021 18:49
start minio for testing with TLS
curl -Ol https://golang.org/src/crypto/tls/generate_cert.go
go run generate_cert.go -ca --host "192.168.86.47"
cp cert.pem key.pem ~/.minio/certs
mv ~/.minio/certs/cert.pem ~/.minio/certs/public.crt
mv ~/.minio/certs/key.pem ~/.minio/certs/private.key
> cat start-https.sh 
export MINIO_ACCESS_KEY="minio"
export MINIO_SECRET_KEY="minio123"
export MINIO_PROMETHEUS_AUTH_TYPE="public"
@crazyguitar
crazyguitar / aws-assume-role.md
Last active July 14, 2021 10:49
AWS assume role

AWS assume role

Based on AWS document, we can use a role on AWS to delegate access AWS resources. For example, we can create a role throw IAM console then grant a permission to access S3 bucket without creating a IAM user. Following steps show how to assume a role to access S3 bucket.

Upload file via temporary credential

Step 1: Create a role to delegate access AWS S3

Install Setup [running on ubuntu 16.04]

1. Install go 1.7.5

sudo apt-get install git 
wget https://storage.googleapis.com/golang/go1.7.5.linux-amd64.tar.gz
tar -C ${HOME} -xzf go1.7.5.linux-amd64.tar.gz

Add the following exports to your ~/.bashrc.

@yairEO
yairEO / jQuery.ajaxRetry.js
Last active January 12, 2022 14:55
jQuery AJAX smart retry
// enhance the original "$.ajax" with a retry mechanism
$.ajax = (($oldAjax) => {
// on fail, retry by creating a new Ajax deferred
function check(a,b,c){
var shouldRetry = b != 'success' && b != 'parsererror';
if( shouldRetry && --this.retries > 0 )
setTimeout(() => { $.ajax(this) }, this.retryInterval || 100);
}
return settings => $oldAjax(settings).always(check)
OS: Ubuntu 16.04
1. Install nginx : nginx version: nginx/1.10.0 (Ubuntu)
2. Install Minio: Follow https://github.com/minio/minio
3. Install MC client: Follow https://github.com/minio/mc
4. Create a bucket:
$ mc mb myminio/static
Bucket created successfully ‘myminio/static’.