Skip to content

Instantly share code, notes, and snippets.

View oleganza's full-sized avatar

Oleg Andreev oleganza

View GitHub Profile
# BEFORE
def access_denied!
throw(:halt, :access_denied)
end
def access_denied(message = "Please sign in first")
case content_type
when :html
store_location
# app/controllers/application/authentication.rb
class Application
module Authentication
module Accessors
# Returns true or false if the user is logged in.
# Preloads @current_person with the Person model if they're logged in.
def logged_in?
!!current_person
end
class ::Object
def hide_inspect_for_one_shot(replacement = "#<#{self.class}:0x#{object_id.to_s(16)}>")
return unless self
mc = class <<self; self; end
mc.send(:alias_method, :inspect_457290, :inspect)
mc.send(:define_method, :inspect) do
mc.send(:alias_method, :inspect, :inspect_457290)
replacement
end
end
In response to all the responses to:
http://twitter.com/rtomayko/status/1155906157
You should never do this in a source file included with your library,
app, or tests:
require 'rubygems'
The system I use to manage my $LOAD_PATH is not your library/app/tests
Oleg Andreev:
щас пишу named args для Io
с ними проблема есть концептуальная:
в руби они как хеши - это удобно
можно передавать туда-сюда
но не очень эффективно
в обж-си они - часть имени метода
их не попередаешь туда-сюда
вопрос: какой подход лучче
/*
The simplest possible state machine implementation in AS3.
Author: Oleg Andreev <oleganza@gmail.com>
Date: March 11, 2009
Example:
// If you single hit spacebar, you just trigger play/pause state.
/* treat double click as a single click (hello, Mom! :-)
function onMouseDown(){
if (!SingleClick()) return
...
}
*/
package pierlis.framework
{
public function SingleClick(delay = SC.DELAY)
#!/usr/bin/env ruby
# Reclone current directory to refresh Flash CS3 brains about classpath
# (after that please do "cd .")
def main
dir = File.dirname(File.expand_path(__FILE__))
dir_basename = File.basename(dir)
dir_basename2 = dir_basename + "-refucking-flash"
origin = sh("git config remote.origin.url").strip
package pierlis.framework
{
import flash.events.*
import fl.transitions.*
import pierlis.framework.*
/*
var tq = new TweenQueue()
tq.push(function(){ new Tween(...) })
tq.push(function(){ new Tween(...) })
// BNF parser framework for JavaScript
// Oleg Andreev
var result = (function(text){
// The Y Combinator
var Y=function (gen) {
return function(f) {return f(f)}(
function(f) {
return gen(function() {return f(f).apply(null, arguments)})})}