Skip to content

Instantly share code, notes, and snippets.

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

Rakesh Patra rakeshpatra

🏠
Working from home
View GitHub Profile
@rakeshpatra
rakeshpatra / transformToFormData.js
Last active July 21, 2023 19:05
Transform nested object to formData
// Using lodash for _.forEach
function transformToFormData(data, formData=(new FormData), parentKey=null) {
_.forEach(data, (value, key) => {
if (value === null) return; // else "null" will be added
let formattedKey = _.isEmpty(parentKey) ? key : `${parentKey}[${key}]`;
if (value instanceof File) {
formData.set(formattedKey, value);
} else if (value instanceof Array){
@rakeshpatra
rakeshpatra / custom_select.js
Last active July 5, 2023 04:32
Configure react-select to hide selected option when clicking on search box or opening menu
import React from "react";
import Select from "react-select";
class CustomSelect extends React.Component {
constructor(props) {
super(props);
this.state = { menuIsOpen: false };
}
@rakeshpatra
rakeshpatra / normalize_rails_locales.sh
Last active September 15, 2020 06:00
i18n-tasks normalize in pre-commit
# using ruby gem "i18n-tasks"
locale_changed=$(git diff --name-only --staged | grep "locales/en.yml")
if [ -n "$locale_changed" ]; then
echo "Locale changed, running i18n-task normalize"
i18n-tasks normalize
git add config/locales/
echo "Done"
fi