Skip to content

Instantly share code, notes, and snippets.

View blahutka's full-sized avatar

blahutka blahutka

View GitHub Profile
@blahutka
blahutka / validations_for.rb
Created September 24, 2024 08:11 — forked from ismasan/validations_for.rb
Declarative AM validations depending on arbitrary attributes
# class Page
# include ValidationsFor
#
# validations_for page_type: 'offer' do
# validates :amount, presence: true
# end
#
# validations_for page_type: 'page' do
# validates :title, presence: true
# end
source 'https://rubygems.org'
# add version numbers with the pessimistic constraint operator to all gems in your Gemfile
# https://github.com/joonty/pessimize
# change also in semaphore.yml and .ruby-version
# before upgrading check if SemaphoreCI supports it already:
# https://docs.semaphoreci.com/reference/semaphore-changelog/
# To prevent forged authentication requests, we need to also include CSRF protection. If you're using OmniAuth with Rails, include:
# disabling for now - we would need to change facebook login to post, but there is client (JS)
# flow and server-side flow and there are differnces in hybrid apps... need to be tested well
# gem 'omniauth-rails_csrf_protection', '~> 0.1'
task_result_stats = {
:task_11 => {
result_count: { neutral: 2, pisitive: 0, negative: 1 },
percent_score: { neutral: '66%', negative: '34%', positive: '0' },
participants: 3,
workers: {
result: { :worker_1 => :neutral, :worker_22 => :neutral, :worker_4 => :negative },
fitness_score: { 1 => 1, 22 => 1, 4 => -1 }
}
@blahutka
blahutka / Tiny JavaScript tokenizer.js
Created November 3, 2017 20:44 — forked from borgar/Tiny JavaScript tokenizer.js
A compact tokenizer written in JavaScript.
/*
* Tiny tokenizer
*
* - Accepts a subject string and an object of regular expressions for parsing
* - Returns an array of token objects
*
* tokenize('this is text.', { word:/\w+/, whitespace:/\s+/, punctuation:/[^\w\s]/ }, 'invalid');
* result => [{ token="this", type="word" },{ token=" ", type="whitespace" }, Object { token="is", type="word" }, ... ]
*
*/
@blahutka
blahutka / docs.rb
Created November 3, 2017 11:54
Hyperloop methods
ReactiveRecord.load
ReactiveRecord::WhileLoading.quiet?
ReactiveRecord::Base.load_data
ReactiveRecord::Base.pending_fetches
React::Server.render_to_string(<Component>)
Model.saving?
React::IsomorphicHelpers.on_opal_client?
React::IsomorphicHelpers.on_opal_server?
@blahutka
blahutka / index.rb
Last active November 3, 2017 11:36
Render from array
# RENDERING FROM ARRAY
# This works
render(DIV) do
@img = Sem.Image(size: 'small', src: 'http://via.placeholder.com/140x100').on(:click) {alert('ok') }
[
@img,
span{'text'}
]
end
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
click(attr, ev) {
console.log('wrapperd');
}
}
});
import Ember from 'ember';
import hbs from 'htmlbars-inline-precompile';
import connect from 'ember-redux/components/connect';
var stateToComputed = (state) => {
return {
number: state.number
};
};
@blahutka
blahutka / Gemfile
Created January 20, 2016 11:33 — forked from terraboops/Gemfile
Simple Mechanize Scraper
source 'https://rubygems.org'
gem 'mechanize'
@blahutka
blahutka / riot_model.js
Last active August 29, 2015 14:21
Riot model
// Source: https://github.com/muut/riotjs/issues/727
var Model = function (attrs) {
// init
this.attributes = attrs || {}
riot.observable(this)
// set method
this.set = function (key, val, options) {