Skip to content

Instantly share code, notes, and snippets.

@DennisMartinez
DennisMartinez / association.rb
Created June 14, 2023 12:53 — forked from itkrt2y/association.rb
Association dataloader with graphql-ruby
# official docs: https://graphql-ruby.org/dataloader/sources.html
# app/graphql/sources/association.rb
class Sources::Association < ::GraphQL::Dataloader::Source
def initialize(association_name, scope = nil)
@association_name = association_name
@scope = scope
end
def fetch(records)
@DennisMartinez
DennisMartinez / font.scss
Last active March 14, 2017 05:06
Font mixin for size / line height / letter spacing. Intended to port fonts from photoshop and convert to rem.
@mixin font($font-size: 15px, $leading: 120%, $letter-spacing: 0) {
@function removeUnit($val) {
@return $val / ($val * 0 + 1)
}
$font-size-no-unit: removeUnit($font-size);
$leading-no-unit: removeUnit($leading);
$letter-spacing-no-unit: removeUnit($letter-spacing);
$font-size-rem: ($font-size-no-unit) / 10;
$leading-rem: ($leading-no-unit) / 10;
@DennisMartinez
DennisMartinez / colorado.svg
Last active March 10, 2017 16:12
include middleware
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@DennisMartinez
DennisMartinez / entry.jsx
Last active March 10, 2017 04:15
Small react component bootstrap
import React from 'react'
import { render } from 'react-dom'
import App from './components/App'
renderReact('#root', App)
function renderReact(htmlSelector, Component) {
Array.from(document.querySelectorAll(htmlSelector))
.forEach(component => render(<Component {...component.dataset} />, component))
}
export function serialize(form, type = 'string') {
const elements = form.elements;
let data = new Map();
[...elements].forEach(element => {
if (!element.value.length) return;
data.set(element.name, element.value);
});
$data = ['dog', 'cat', 'rabbit', 'bird'];
$max_per_row = 2;
foreach (array_chunk($data, $max_per_row) as $rows) {
echo '<div class="row">';
foreach ($rows as $column)
echo '<div class="column">', $column, '</div>';
echo '</div>';
@DennisMartinez
DennisMartinez / Test
Created April 17, 2014 19:00
Fit a set of coords to the screen in Google Maps
var locations = [
new google.maps.LatLng(43.5944677, -83.8888647),
new google.maps.LatLng(43.1775256, -83.73412739999998),
new google.maps.LatLng(43.4194699, -83.95080680000001),
new google.maps.LatLng(43.0125274, -83.68745619999999),
new google.maps.LatLng(42.732535, -84.55553470000001)
];
// fit the points in a bounds and zoom.
fitBounds(locations);
@DennisMartinez
DennisMartinez / gist:7161616
Created October 25, 2013 20:50
Template Test
<script>
CKEDITOR.stylesSet.add('CustomStyle', [
{
name: 'Page Title',
element: 'h1',
styles: {
'color': '#222'
}
}
]);
@DennisMartinez
DennisMartinez / gist:7100963
Created October 22, 2013 13:40
animated gradients
.background(@background: @blue) {
.gradient > .linear(@background, @background);
background-size: 1px 34px;
}
.text-shadow(@color: @blue) {
text-shadow: 0 1px 0 darken(@color, 15%);
}
.hover() {