Skip to content

Instantly share code, notes, and snippets.

View bargar's full-sized avatar

Jeremy Bargar bargar

  • Formiga Consulting
  • Brooklyn, NY
View GitHub Profile
@bargar
bargar / color.swift
Created August 15, 2018 21:30
determine if light or dark foreground is better for a given background color
// inspiration: https://stackoverflow.com/a/3943023/558780
// wc3 approach
public static func favorsDarkForeground(_ bgColor: UIColor) -> Bool {
if let rgb = bgColor.rgb() {
var uicolors: Array<Float> = [Float(rgb.red) / 255, Float(rgb.green) / 255, Float(rgb.blue) / 255];
var c = uicolors.map({ (uicolor) -> Float in
if (uicolor <= 0.03928) {
@bargar
bargar / routes.application.js
Last active November 7, 2016 19:41
Extending Computed Properties
import Ember from 'ember';
export default Ember.Route.extend({
model() {
// object with computed property
var Parent = Ember.Object.extend({
fullName: Ember.computed('first', 'last', function() {
return `${this.get('first')} ${this.get('last')}`;
})
@bargar
bargar / minimally-styled-webkit-scrollbars.scss
Created June 15, 2016 18:30
minimal but more pleasant scrollbar styling for webkit
// blend in with background, less visually jarring than native
$scrollbar-size: 7px;
::-webkit-scrollbar {
background-color: $background-color;
width: $scrollbar-size;
height: $scrollbar-size;
}
::-webkit-scrollbar-thumb {
background:#999;
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle',
actions: {
greet: function(friend) {
window.alert(`Hello, ${friend}!`);
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return 'Sandwich';
}
});
@bargar
bargar / recursiveReplaceKey
Last active August 29, 2015 14:21
Rename key wherever found within an object
var recursiveReplaceKey = function(object, oldKey, newKey) {
for (var key in object) {
if (object.hasOwnProperty(key)) {
if ($.isPlainObject(object[key])) {
// recurse to sub-object
util.recursiveReplaceKey(object[key], oldKey, newKey);
}
if (key === oldKey) {