Skip to content

Instantly share code, notes, and snippets.

Zachary Friedman kulte

Block or report user

Report or block kulte

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 pure-impure-1.js
// Examples of pure functions. No side effects. No mutations.
function square(x) {
return x * x;
}
function squareAll(items) {
return items.map(square);
}
// Examples of impure functions.
View ams_endpoint.rb
class FoosController < ApplicationController
def index
@collection = Foo.all
render json: @collection, fields: params[:fields]
end
end
class FooSerializer < ActiveModel::Serializer
cache key: 'foo'
View akon.html.haml
- Akon.perform
- content_for :javascript do
:javascript
window.sing(jQuery(jQuery("bill y'all")));
@kulte
kulte / uninstall_homebrew.sh
Created May 3, 2015
uninstall_homebrew.sh
View uninstall_homebrew.sh
#!/bin/sh
# Just copy and paste the lines below (all at once, it won't work line by line!)
# MAKE SURE YOU ARE HAPPY WITH WHAT IT DOES FIRST! THERE IS NO WARRANTY!
function abort {
echo "$1"
exit 1
}
set -e
@kulte
kulte / create_project.rb
Last active Aug 29, 2015
interactor-demo
View create_project.rb
class CreateProject
include Interactor
def call
context.project = context.controller.current_user.projects.build(context.project_params)
if context.project.save
context.notice = 'Your project was created successfully.'
send_emails_for(context.project)
else
@kulte
kulte / types.swift
Created Oct 14, 2014
Swift is very strict about types
View types.swift
let jsonObject : AnyObject! = NSJSONSerialization.JSONObjectWithData(dataFromTwitter, options: NSJSONReadingOptions.MutableContainers, error: nil)
if let statusesArray = jsonObject as? NSArray{
if let aStatus = statusesArray[0] as? NSDictionary{
if let user = aStatus["user"] as? NSDictionary{
if let userName = user["name"] as? NSDictionary{
//Finally We Got The Name
}
}
}
@kulte
kulte / harmful_callbacks.rb
Created Mar 27, 2014
Using ActiveRecord::Callback and wrapping your create with a transaction will execute your after_create before the transaction finishes.
View harmful_callbacks.rb
class User < ActiveRecord::Base
after_create :send_welcome_email
private
def send_welcome_email
UserMailer.welcome_email(self).deliver
end
end
View up_yours_capybara.rb
source = page.all('.item').last
target = page.all('.item').first
while source.nil?
source = page.all('.item').last
end
while target.nil?
target = page.all('.item').first
end
View promise.js
"use strict"
var Promise = function () {
this.state = 'pending'
this.thenables = []
}
Promise.prototype.resolve = function (value) {
if (this.state != 'pending') return
this.state = 'fulfilled'
View git-1.sh
git checkout bcee89a90aad3877da531d6cb10ca91c6155d577 -- app/assets/images/sales
You can’t perform that action at this time.