Skip to content

Instantly share code, notes, and snippets.

View varyform's full-sized avatar

Oleh Khomei varyform

View GitHub Profile
@varyform
varyform / new.html.haml
Created August 27, 2012 20:23
Photo picker with live preview
%div.tac
-# remotipart for ajax image upload
= form_for Parent.new, url: upload_parent_photo_path, remote: true, html: { id: 'file-form' } do |f|
#temp-photo.tac{ style: "position: relative; background: url('#{image_path(resource.avatar.url(:thumb))}') center center no-repeat; height: 120px" }
-# prompt
= link_to '#', class: 'btn btn-mini btn-light', style: 'opacity: 0.9; position: absolute; bottom: 0; left: 50%; width: 100px; margin-left: -55px' do
Choose Photo
-# almost transparent file field which actually receives mouse click and "covers" link above
= f.file_field :avatar, id: 'temp-avatar', style: 'position: absolute; cursor: pointer; opacity: 0.01; top: 0; left: 0; width: 100%; height: 100%; '
@varyform
varyform / quantize.js
Created September 17, 2013 11:08 — forked from cwey/quantize.js
/*!
* quantize.js Copyright 2008 Nick Rabinowitz.
* Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
*/
// fill out a couple protovis dependencies
/*!
* Block below copied from Protovis: http://mbostock.github.com/protovis/
* Copyright 2010 Stanford Visualization Group
* Licensed under the BSD License: http://www.opensource.org/licenses/bsd-license.php
@varyform
varyform / fib.rb
Created April 17, 2014 21:56
fib with memo
# Fibonacci numbers WITH memoization.
# Initialize the memoization array.
@scratchpad = []
# Calculate the nth Fibonacci number, f(n).
def fibo(n)
if n <= 1
n
else
###
# DO YOU HEAR THE PEOPLE SING? (Uplifting Mix)
# version 1.3 (clearer kick sound)
#
# Converted from CoffeeScript
# Source: https://gist.github.com/11080149
# Usage: coffee -bcp file.coffee
#
# Original from Les Miserables
@varyform
varyform / file_ext.css.scss
Created March 13, 2015 17:11
CSS file extension
// usage:
// .file-extension
// %span TXT
body {
background: #f0f0f0;
padding: 2em;
}
.file-extension {
@varyform
varyform / generator.rb
Last active August 29, 2015 14:17
SVG extension icon generator
require 'color'
require 'digest/md5'
def generate(extension)
color = Digest::MD5.hexdigest(extension)[0..5]
hsl = Color::RGB.from_html(color).to_hsl
hue = hsl.hue / 360.0
sat = 0.52
lit = hsl.lightness / 100
@varyform
varyform / register_statistics.rake
Created February 6, 2017 18:39 — forked from jsborjesson/register_statistics.rake
Add more folders to rake stats
task :register_statistics do
require 'rails/code_statistics'
STATS_DIRECTORIES << ['Services', 'app/services']
STATS_DIRECTORIES << ['Services Tests', 'test/services']
CodeStatistics::TEST_TYPES << 'Services Tests'
end
Rake::Task['stats'].enhance [:register_statistics]

Keybase proof

I hereby claim:

  • I am varyform on github.
  • I am varyform (https://keybase.io/varyform) on keybase.
  • I have a public key ASBmTI-kjeMgaHsbQGMwHclPhC7mSW6OEkBKy0RVeGk9Xgo

To claim this, I am signing this object:

wins = [
# rows
0b000000111,
0b000111000,
0b111000000,
# cols
0b100100100,
0b010010010,
0b001001001,
# diags
@varyform
varyform / 2.rb
Created December 7, 2021 11:19
Advent of code 2021 day 6 part 2
fish = Hash.new(0).merge(DATA.read.chomp.split(',').map(&:to_i).tally)
256.times do
-1.upto(8) { |day| fish[day] = fish[day + 1] }
born = fish.delete(-1)
fish[8] += born
fish[6] += born
end