Skip to content

Instantly share code, notes, and snippets.

View yonbergman's full-sized avatar

Yonatan Bergman yonbergman

View GitHub Profile
@yonbergman
yonbergman / machine.js
Last active November 27, 2020 08:09
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@yonbergman
yonbergman / template.rb
Created September 15, 2014 10:09
Rails Workshop template
# Source: https://github.com/Ben-M/simple_scaffold
def generate_controller(update_method, params, include_white_list_code=false)
strong_params_method=white_list_code if include_white_list_code
controller_code = <<-CODE
<% if namespaced? -%>
require_dependency "<%= namespaced_file_path %>/application_controller"
<% end -%>
<% module_namespacing do -%>
class <%= controller_class_name %>Controller < ApplicationController
@yonbergman
yonbergman / primer.rb
Created July 29, 2013 19:07
Prime Numbers Kata • Ruby Undergroud
class Primer
attr_accessor :num
def initialize(num)
@num = num
end
def run
arr = []
@yonbergman
yonbergman / dst.coffee
Created November 2, 2011 08:52
Dynamically Shrinking Titles
# insert this somewhere right after document.load
@header = $('.header')
while (@header.height() > @header.parent().height())
currentFontSize = parseInt(@header.css("font-size"))
@header.css("font-size", currentFontSize - 1)
@yonbergman
yonbergman / noodge.rb
Created June 19, 2011 21:15
How to get someone's attention without disturbing everyone
require 'net/http'
require 'digest/md5'
# USAGE: noodge.rb bob #send 'nudge' to bob
# noodge.rb alice 'hi alice' # sends 'hi alice' to alice
# noodge.rb alice 'bye alice' bob # send 'bye alice' to alice as bob
# each time you send as someone (via 3rd param or via application request) it will save your name into the config so that next time you won't need to set it.
API_KEY = "YOUR Notify.io API KEY"
NOODGE_FILE = ".noodge_user" # A config file to hold the FROM user
# SCIL 7 - DSL Exercise in python
# done by @yonbergman and @avihut
# Usage:
# c = Cart()
# c.items()
# => [<foo(100)>,<bar(50)>]
# c.run_rules()
# c.items()
# => WIN
class User < ActiveRecord::Base
enum :role, [:admin,:moderator,:user]
# You can optionally add this function to your model
# and it will be called after each change of the role for callbacks you might need
def role_changed(from,to)
puts "The role changed from #{from} to #{to}"
end
end