Skip to content

Instantly share code, notes, and snippets.

View firedev's full-sized avatar
👁️
👁

Nick Ostrovsky firedev

👁️
👁
View GitHub Profile
require 'ostruct'
css = File.read('apps/src/stylesheets/sagamore/_buttons.scss').split("\n")
find_images = -> line { line[/"(.+)"/]; $1 }
check_for_file = -> name { OpenStruct.new(name: name, exists: File.exists?("apps/src/images/icons/#{name}.png")) }
format_filenames = -> file_exists { OpenStruct.new(name: (file_exists.name + '.png' + ' ' * 20)[0, 20], exists: file_exists.exists) }
print_results = -> file_exists { puts "#{file_exists.name}\t #{file_exists.exists ? '✅' :'⛔'}" }
css.map(& find_images).compact.map(& check_for_file).map(& format_filenames).map(& print_results)
class BottomlessHash < Hash
def initialize
super &-> h, k { h[k] = self.class.new }
end
def self.from_hash(hash)
new.merge(hash)
end
end
@firedev
firedev / colors.rb
Last active April 15, 2016 09:41
Colors.rb – Functional programming in Ruby example
#!/usr/bin/env ruby
require 'paleta'
to_paleta = ->(color) { Paleta::Color.new(:hex, color) rescue nil }
to_div = ->(str) {
"<div style='font-family: sans-serif; width: 5em; height: 3em;
line-height: 3em; display: inline-block; text-align: center;
margin: 0.25em; border-radius: 0.25em; padding: 1em;
background: ##{str}'>
@firedev
firedev / gist:5bc7de39c7407eaad105
Last active August 29, 2015 14:22
React Searchbox in CoffeeScript
# global $
React = require('react')
class Drawer extends React.Component
@defaultProps: ->
payload: null,
drawerOpened: false
notFound: ->
import React, { Component } from 'react';
class Drawer extends Component {
getDefaultProps() {
return {
payload: null,
drawerOpened: false
};
};
months:
['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
render: ->
DOM.select
onChange: @onMonthChange
value: @props.date.getMonth()
DOM.option(
value: i, key: i, @months[i]
) for i in [0..(@months.length-1)]
@firedev
firedev / color_order.rb
Created April 29, 2015 04:17
Ruby functional-style palette maker
require 'paleta'
colors = %w( 669900 66FF00 66CCFF 6699FF 6633FF )
to_color = ->(color) { Paleta::Color.new(:hex, color) }
to_div = ->(color) { "<div style='width: 3em; height: 3em; background: ##{color}; float: left'></div>" }
puts colors.uniq.map(& to_color).sort_by(&:hue).map(&:hex).map(& to_div)
@firedev
firedev / Gruntfile.coffee
Created April 1, 2015 06:18
Gruntfile for setting up Slim, SASS and Coffeescript compilation to public folder
module.exports = (grunt) ->
# configuration
grunt.initConfig
# grunt sass
sass:
compile:
options:
style: 'expanded'
@firedev
firedev / equalizer.coffee
Created March 23, 2015 02:51
Height Equalizer – new Equializer('.elements') will keep all elements the same height
class @Equalizer
constructor: (selector) ->
@init $(selector)
init: ($collection)->
@attachTo($collection) if $collection.length
attachTo: ($collection) ->
@collection = $collection
@setTimeoutFunction(@equalizeHeight, @collection)
@firedev
firedev / blocks.rb
Last active August 29, 2015 14:17
Blocks
class Page
has_many :blocks, -> { ordered }, dependent: :destroy
attr_accessors :title
def visible_blocks
@visible_block ||= blocks.current_locale.map(&:blockable)
end
end
class Block