Skip to content

Instantly share code, notes, and snippets.

Tony Schneider tonywok

Block or report user

Report or block tonywok

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am tonywok on github.
  • I am tonywok (https://keybase.io/tonywok) on keybase.
  • I have a public key ASBcoIdY2d_xFoFbXJyD0jt9pJCvZj3e2lIltd14lQcLKQo

To claim this, I am signing this object:

View dag_spike.rb
require "tsort"
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'pry'
gem 'pry-byebug'
end
@tonywok
tonywok / rpn.rb
Created Oct 13, 2018
Toy RPN Expression Evaluator
View rpn.rb
require "forwardable"
class Operator
# TODO: probably raise if stuff isn't implemented
# TODO: probable register implementations
end
class Operand
# TODO: probably raise if stuff isn't implemented
# TODO: probable register implementations
View acronym.exs
module Acronym
def abbreviate(string) do
string
|> String.codepoints
|> Enum.with_index
|> Enum.reduce("", fn({letter, idx}, acronym) ->
cond do
String.upcase(letter) == letter and String.downcase(letter) != letter ->
acronym <> letter
String.at(string, idx-1) == " " ->
@tonywok
tonywok / stolen-laptop.md
Last active Sep 25, 2015
Preparing for your laptop to be stolen
View stolen-laptop.md

Preparing for your Laptop to be stolen by some Asshole

Note, at the time of writing this, I use a mac. Adjust to your preference.

Assumptions

If you're reading this and haven't done these things, and your laptop is still in your possession. Stop everything and do them now.

  1. You have an encrypted hard drive (e.g FileVault)
@tonywok
tonywok / gist:d4395f242e8b29f3f126
Last active Aug 29, 2015
More Flexible User Models
View gist:d4395f242e8b29f3f126

More Flexible Users

Applications are built for users. We give them distinguishing properties, connect them to other entities, respond to their actions, and make various decisions based on any combination of those things.

In rails, it's almost guaranteed that sitting inside of app/models/ is a class called User. I'm sure you're intimately familiar with this class. In fact, I suspect that if you were to hack together a heat-map representing your code editor, user.rb would probably be molten.

The Setup

Taking this into consideration, how would you describe the responsibility of your User model? I've noticed a few trends while working in rails:

@tonywok
tonywok / gist:a954531b5395d52ead6f
Created Jun 23, 2014
Some helpers for dealing with missing data and handling defaults w/o making a bunch of nested if/else
View gist:a954531b5395d52ead6f
Neo.UI.Mixin.Maybe =
maybeAnchored: (bool, url, dom...) ->
if bool
React.DOM.a(href: url, dom)
else
dom
maybeDisplayed: (bool, dom...) ->
if bool then dom else null
View ember data jsbin
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ember Starter Kit</title>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/2.1.0/normalize.css">
</head>
<body>
<script type="text/x-handlebars">
@tonywok
tonywok / active_model_serializer.rb
Created Apr 2, 2014
Hacking polymorphic has_many into AMS. (e.g has_many :tasks, embed: :ids, include: true, polymorphic: true)
View active_model_serializer.rb
module ActiveModel
class Serializer
module Associations
class HasMany
def key_with_polymorphism
return @name if !option(:key) && option(:polymorphic)
key_without_polymorphism
end
alias_method_chain :key, :polymorphism
View jsbin.fuxijasi.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ember Starter Kit</title>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/2.1.0/normalize.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.2.1.js"></script>
<script src="http://builds.emberjs.com/tags/v1.4.0/ember.js"></script>
</head>
You can’t perform that action at this time.