Skip to content

Instantly share code, notes, and snippets.

View mreigen's full-sized avatar

Minh Reigen mreigen

  • Orange County / Los Angeles
View GitHub Profile
@mreigen
mreigen / active_admin.en.yml
Last active March 13, 2018 15:15 — forked from a-chernykh/active_admin.en.yml
Add "not equals" option to ActiveAdmin string filter
# in my experience, adding this will duplicate the filter list next to the input
en:
active_admin:
filters:
predicates:
not_eq: "Not equals"
@mreigen
mreigen / app.js
Last active April 10, 2018 17:38
Goal: 1) To remove the # hash from the url. 2) Shareable on Facebook, twitter... with dynamic meta tags
//AngularJS app
.config( function myAppConfig ($locationProvider) {
$locationProvider.html5Mode(true);
...
}
@mreigen
mreigen / animal_serializer.rb
Created July 1, 2017 22:11
Rails Serializer: Custom attributes based on passed in options
class AnimalSerializer < ActiveModel::Serializer
def initialize(object, options)
if options[:type] == 'giraffe'
self.class.attributes :skin_pattern, :leg_length
else
self.class.attributes :number_of_legs
end
super(object, options)
end
...
@mreigen
mreigen / generate-alphabets.js
Created November 20, 2017 05:55
Javascript generate alphabet string
function generateAlphabets() {
var alphabets = [];
var start = 'A'.charCodeAt(0);
var last = 'Z'.charCodeAt(0);
for (var i = start; i <= last; ++i) {
alphabets.push(String.fromCharCode(i));
}
return alphabets.join('');
}
@mreigen
mreigen / routes.rb
Created May 25, 2018 19:52
Example of splitting a main routes file into smaller route files
Rails.application.routes.draw do
# ...
draw :v1
draw :v2
# ...
end
const key1 = "make";
const key2 = "model;
const newObj = {
year: 2020,
[key1]: "toyota"
[key2]: "prius"
}
const name = "com";
let i = 1;
const radioDevice = {
numberOfComs: 3,
[name + "_" + i++]: "port 4556",
[name + "_" + i++]: "socket 12",
[name + "_" + i++]: "socket 15",
};
let array = [
{name: "Minh", age: 20},
{name: "Brian", age: 22},
{name: "Hugo", age: 12},
{name: "Zelda", age: 56},
{name: "Simon", age: 7}
];
const nameToFind = "Hugo";
const personToReplace = {name: "Ali", age: 34};
@mreigen
mreigen / auto-save-react-old-code.js
Created June 1, 2020 17:01
old code to auto save text using debounce
import { debounce } from "lodash";
import RichText from "../controls/rich_text";
...
class TextQuestion extends React.Component {
constructor(props) {
super(props);
this.update = debounce(this._update.bind(this), 500);
}
@mreigen
mreigen / auto-save-react-new-code.js
Created June 1, 2020 17:09
Auto save in ReactJS using setTimeout
import RichText from "../controls/rich_text";
const SavingState = Object.freeze({
NOT_SAVED: 0,
SAVING: 1,
SAVED: 2
});
class TextQuestion extends React.Component {
constructor(props) {