Skip to content

Instantly share code, notes, and snippets.

View crrmacarse's full-sized avatar
✍️
@ bitbucket

Macarse, Christian Ryan R. crrmacarse

✍️
@ bitbucket
View GitHub Profile
@crrmacarse
crrmacarse / queryString.js
Last active January 28, 2020 07:43
Custom query string creator and builder!
export const getQueryString = string => {
const newString = string.trim().replace(/^\?/, '')
const splittedAmpersandArr = newString.split('&')
let queryStringObj = {}
splittedAmpersandArr.forEach(value => {
const indexOfEqual = value.indexOf('=')
const key = value.slice(0, indexOfEqual)
const val = value.slice(indexOfEqual + 1, value.length)
const isArr = /[\[\]]{2}$/.test(key)
@crrmacarse
crrmacarse / pluralize.js
Last active January 28, 2020 07:41
Pluralize a word!
const pluralize = word => {
const wordArr = word.split('')
const suffix = wordArr.pop()
switch (suffix) {
case 's':
case 'z':
case 'x':
return `${wordArr.join('')}${suffix}es`
case 'y':
@crrmacarse
crrmacarse / hasDom
Last active January 28, 2020 07:32
Validate If the current environment is a browser
const hasDom = (typeof window !== 'undefined' && typeof document !== 'undefined')
export default hasDom
@crrmacarse
crrmacarse / geoLocation.js
Last active January 28, 2020 07:32
Get current location of User
export default () => {
try {
const geoLocation = navigator.geolocation;
return new Promise((resolve, reject) => {
geoLocation.getCurrentPosition(resolve, reject, {
enableHighAccuracy: true,
});
});
} catch (error) {
@crrmacarse
crrmacarse / cropHelper.js
Last active January 28, 2020 07:41
Image Crop Helper
export const scaleX = (baseWidth, width) => Math.round(baseWidth / width);
export const scaleY = (baseHeight, width) => Math.round(baseHeight / width);
export const cropXvalue = (x, scaleXvalue) => Math.round(x * scaleXvalue);
export const cropYvalue = (y, scaleYvalue) => Math.round(y * scaleYvalue);
export const cropWidthValue = (width, scaleXValue) => Math.round(width * scaleXValue);
export const cropHeightValue = (height, scaleYValue) => Math.round(height * scaleYValue);
@crrmacarse
crrmacarse / iimageCompressor.js
Last active January 27, 2020 23:41
Image Compressor
import imageCompressor from 'browser-image-compression'
const blobToFile = async (blob, file) => {
const result = new File([blob], file.name, { type: file.type, lastModified: Date.now() });
return result
}
const compressImage = async (maxWidth, file) => {
const options = {
maxWidthOrHeight: maxWidth,
name: CI
on: [push]
jobs:
test:
name: Test on node ${{ matrix.node }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
@crrmacarse
crrmacarse / navigation.js
Created January 28, 2020 07:26
Toggling of components without changing of route. The awesome stuff? selected state persist still even on route change!
// Implemented here: https://crrmacarse.github.io/personal
// NOTE:
// It could probably lead to a bug when you try to add multiple of these across components
// link routes that'll will assure of state existence
<Link to={(location) => ({ ...location, pathname: 'go' })}>Go</Link>
<Link to={(location) => ({ ...location, pathname: 'current' })}>Current</Link>
// to pass a state value to the current path
name: Release
on:
push:
branches:
- source
env:
NODE_ENV: production
PUBLIC_URL: http://crrmacarse.github.io/
import { join, resolve } from 'path';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
export const entry = join(process.cwd(), '/src/index.tsx');
export const output = {
path: join(process.cwd(), '/dist'),
filename: '[name].[hash].bundle.js',
chunkFilename: '[name].[hash].bundle.js',