Skip to content

Instantly share code, notes, and snippets.

@Morganjackson
Morganjackson / json_map_builder.ex
Last active November 18, 2016 08:53 — forked from rcdilorenzo/json_map_builder.ex
Convert a elixir json-decoded object to a map no matter how deep
defmodule JSONMapBuilder do
def to_map(list) when is_list(list) and length(list) > 0 do
case list |> List.first do
{_, _} ->
Enum.reduce(list, %{}, fn(tuple, acc) ->
{key, value} = tuple
Map.put(acc, binary_to_atom(key), to_map(value))
end)
_ ->
list
export function convertHexToRgba(originalHex, opacity) {
const hex = originalHex.replace('#', '')
const r = parseInt(hex.substring(0, 2), 16)
const g = parseInt(hex.substring(2, 4), 16)
const b = parseInt(hex.substring(4, 6), 16)
const rgba = `rgba(${r}, ${g}, ${b}, ${opacity})`
return rgba
}
export function convertHexToRgb(originalHex) {
@Morganjackson
Morganjackson / App.js
Created March 29, 2017 21:20 — forked from Sivli-Embir/App.js
A drop in solution to getting dynamic import React components in Meteor 1.5
import React from 'react';
import AsyncComponent from './AsyncComponent'
// call this.getAsyncComponent(path) to get a default export.
// call this.getAsyncComponent(path, specifier) to get a non-default export.
class App extends AsyncComponent {
render() {
let view;
export function setTextColor(color) {
const rgb = convertHexToRgb(color)
const gamma = 2.2
const luminosity =
0.2126 * Math.pow(splitRgb(rgb).r, gamma) +
0.7152 * Math.pow(splitRgb(rgb).g, gamma) +
0.0722 * Math.pow(splitRgb(rgb).b, gamma)
if (luminosity < 0.6) return '#FFFFFF'
return '#282828'
}
// meteor algorithm to check if this is a meteor serving http request or not
function IsAppUrl(req) {
var url = req.url;
if(url === '/favicon.ico' || url === '/robots.txt') {
return false;
}
// NOTE: app.manifest is not a web standard like favicon.ico and
// robots.txt. It is a file name we have chosen to use for HTML5
// appcache URLs. It is included here to prevent using an appcache
@Morganjackson
Morganjackson / actionTypeBuilder.js
Created May 17, 2017 09:39 — forked from dbismut/actionTypeBuilder.js
React Redux Meteor middlewares
export function actionTypeBuilder(prefix) {
return {
type: actionType => `${prefix}/${actionType}`,
loading: actionType => `${actionType}/loading`,
ready: actionType => `${actionType}/ready`,
stopped: actionType => `${actionType}/stopped`,
changed: actionType => `${actionType}/changed`,
error: actionType => `${actionType}/error`,
success: actionType => `${actionType}/success`
};
@Morganjackson
Morganjackson / actionTypeBuilder.js
Created May 17, 2017 09:39 — forked from smeijer/actionTypeBuilder.js
React Redux Meteor middlewares
export function actionTypeBuilder(prefix) {
return {
type: actionType => `${prefix}/${actionType}`,
loading: actionType => `${actionType}/loading`,
ready: actionType => `${actionType}/ready`,
stopped: actionType => `${actionType}/stopped`,
changed: actionType => `${actionType}/changed`,
error: actionType => `${actionType}/error`,
success: actionType => `${actionType}/success`
};
const createAdSet = async (fbCampaignId, campaign) => {
try {
const data = {
[AdSet.Fields.campaign_id]: fbCampaignId,
[AdSet.Fields.name]: `${campaign.name} Ad Set`,
[AdSet.Fields.optimization_goal]: 'BRAND_AWARENESS',
[AdSet.Fields.billing_event]: 'IMPRESSIONS',
[AdSet.Fields.is_autobid]: true,
// [AdSet.Fields.bid_amount]: 2, // TODO: Write a conversion method to calculate budget based on end date of campaign.
describe Simulator do
let(:table) { Table.new(5, 5) }
let(:simulator) { described_class.new(table) }
it "places the robot onto a valid position" do
simulator.place(0, 0, "NORTH")
expect(simulator.robot).to be_a(Robot)
end
it "places the robot onto a invalid position" do