Skip to content

Instantly share code, notes, and snippets.

# Potential solution to "Using accepts_nested_attributes_for with a belongs_to association, and using find_or_create_by_attr behaviour"
# http://stackoverflow.com/questions/2970255/using-accepts-nested-attributes-for-with-a-belongs-to-association-and-using-find
class Upload < AR:B
belongs_to :user
belongs_to :observed_property
belongs_to :sensor
attr_accessor :observed_property_attributes,
:sensor_attributes
attr_accessible :observed_property_attributes,
@codeswimmer
codeswimmer / CustomView_drawGradient.m
Created November 16, 2011 22:17
iOS: Draw gradient fill
-(void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrnetContext();
CGGradientRef gradient = [self gradient];
CGPoint startPoint = CGPointMake(CGRectGetMidX(self.bounds), 0.0);
CGPoint endPoint = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMaxY(self.bounds));
CGContextDrawLinearGradient(context, gradient, startPoint, endPoint);
}
-(CGGradientRef)gradient
For those folks not already hanging out in #documentcloud... here's the log of this afternoon's Ember/Backbone politics discussion.
12:21 PM <wycats> jashkenas: hey
12:21 PM <wycats> jashkenas: I'm sorry
12:21 PM <wycats> how would you like me to describe backbone?
12:21 PM <wycats> let's work this out for once and for all :)
12:21 PM <wycats> I'm definitely not intentionally saying incorrect things about backbone
12:22 PM • knowtheory gets out popcorn
12:24 PM <jashkenas> don't worry about it too much -- I'm just not terribly pleased with backbone being continued to be used as the strawman...
12:24 PM <wycats> jashkenas: I am worried about it a lot
#!/bin/sh
# on osx lion, this is a great way to listen to this in the background. make sure to download and
# install sangeeta and tom and karen in system preferences. feel free to change the voices to your
# suiting, but sangeeta is a fave of mine for almost everything.
say -v Sangeeta "hey"
say -v Sangeeta "I'm sorry"
say -v Sangeeta "how would you like me to describe backbone?"
say -v Sangeeta "let's work this out for once and for all :)"
@domenic
domenic / q-mongoose-so.js
Last active August 24, 2017 05:49
Q + Mongoose from StackOverflow
var mongoose = require('mongoose');
mongoose.connect('mongo://localhost/test');
var conn = mongoose.connection;
var users = conn.collection('users');
var channels = conn.collection('channels');
var articles = conn.collection('articles');
var insertUsers = Q.nfbind(users.insert.bind(users));
var insertChannels = Q.nfbind(channels.insert.bind(channels));
@waterlink
waterlink / devise.rb
Created March 16, 2014 15:19
Rspec Devise helper with support for routing :authenticated and :unauthenticated tests
# spec/support/devise.rb
module Devise::RoutingTestHelpers
attr_accessor :request
def initialize(*args)
@request ||= Hashie::Mash.new env: {}
super(*args)
end
@marcoarment
marcoarment / ATPLogoView.m
Created April 29, 2014 21:07
Source for the Accidental Tech Podcast (ATP) T-Shirt
// Source for the Accidental Tech Podcast (ATP) T-Shirt:
// http://www.marco.org/2014/04/29/atp-shirts
//
// By Marco Arment, April 28, 2014. MIT license.
@implementation ATPLogoView
- (void)drawRect:(CGRect)rectIgnored
{
NSString *fontName = @"MyriadPro-Semibold";
@scottjehl
scottjehl / noncritcss.md
Last active August 12, 2023 16:57
Comparing two ways to load non-critical CSS

I wanted to figure out the fastest way to load non-critical CSS so that the impact on initial page drawing is minimal.

TL;DR: Here's the solution I ended up with: https://github.com/filamentgroup/loadCSS/


For async JavaScript file requests, we have the async attribute to make this easy, but CSS file requests have no similar standard mechanism (at least, none that will still apply the CSS after loading - here are some async CSS loading conditions that do apply when CSS is inapplicable to media: https://gist.github.com/igrigorik/2935269#file-notes-md ).

Seems there are a couple ways to load and apply a CSS file in a non-blocking manner:

@noelboss
noelboss / git-deployment.md
Last active June 12, 2024 00:28
Simple automated GIT Deployment using Hooks

Simple automated GIT Deployment using GIT Hooks

Here are the simple steps needed to create a deployment from your local GIT repository to a server based on this in-depth tutorial.

How it works

You are developing in a working-copy on your local machine, lets say on the master branch. Most of the time, people would push code to a remote server like github.com or gitlab.com and pull or export it to a production server. Or you use a service like deepl.io to act upon a Web-Hook that's triggered that service.

@zappycode
zappycode / NSImageToJpeg.swift
Last active June 12, 2024 02:15
Coverting an NSImage into JPEG Data
func jpegDataFrom(image:NSImage) -> Data {
let cgImage = image.cgImage(forProposedRect: nil, context: nil, hints: nil)!
let bitmapRep = NSBitmapImageRep(cgImage: cgImage)
let jpegData = bitmapRep.representation(using: NSBitmapImageRep.FileType.jpeg, properties: [:])!
return jpegData
}