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 / 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 / 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 / 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",
};
@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);
}
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};
describe "make_dish_from_left_over" do
context "with dishes that are served cold" do
# before: set up cold dishes
# ...
# end
context "seasoning available" do
# before: set up seasoning
# ...
# end
expect(add_seasoning).to be_truthy
defp setup_cold_dishes(context) do
temp = 35
size = if context.size, do: size, else: :small
dish = set_temperature(temp)
|> set_size(size)
|> set_time_in_fridge(:15_hours)
|> build_dish
%{temp: temp, size: size, cold_dish: dish}
end