Skip to content

Instantly share code, notes, and snippets.

@nickw
nickw / Button.js
Last active November 1, 2021 17:55
Cross-platform Button component for React Native
import React, { Component } from 'react';
import {
Text,
View,
Platform,
TouchableHighlight,
TouchableOpacity,
TouchableNativeFeedback,
} from 'react-native';
define(‘sayHello’, function(name) {
return function(name) {
alert(‘Hi ‘ + name + ‘!’);
}
});
@nickw
nickw / sinatra_new_relic_1.rb
Created March 18, 2013 21:03
sinatra_new_relic_1.rb sets up New Relic in the config.ru <br> sinatra_new_relic_2.rb sets up New Relic in the Sinatra App
# server.rb
$: << File.expand_path(File.dirname(__FILE__) + "/../lib")
require "sinatra/base"
require "newrelic_rpm"
module CrowdHall
class Server < Sinatra::Base
configure do
set :app_file, __FILE__
View
clickVote: (event)->
direction = event.direction
oppositeDirection = if direction is "up" then "down" else "up"
if currentUser.hasVoted(@model, direction)
@model.removeVote(direction)
else
if currentUser.hasVoted(@model, oppositeDirection)
@model.removeVote(oppositeDirection)
CH.Concerns.Voteable =
incrementScore: ->
score = parseInt(@get("score"), 10)
@set "score", score+1
decrementScore: ->
score = parseInt(@get("score"), 10)
@set "score", score-1
class CH.Views.PostFormView extends Backbone.View
events:
"focus #post_title": "focus"
initialize: ->
$("body").on "click", (event) => @blur(event)
focus: ->
@$(".post-form-expanded").show()
@nickw
nickw / jquery.myplugin.coffee
Created April 24, 2012 01:49 — forked from jimeh/jquery.myplugin.coffee
Example jQuery plugin written in CoffeeScript, and the resulting compiled JavaScript file.
$.fn.extend
myplugin: (options) ->
self = $.fn.myplugin
opts = $.extend {}, self.defaultOptions, options
for el in this
self.init el, opts
self.log el if opts.log
$.extend $.fn.myplugin,
.browser {
h3 {
margin-bottom: 10px;
}
ol {
@include pie-clearfix;
}
}
@nickw
nickw / gist:1043436
Created June 23, 2011 19:38
Permissions Query
def viewable_by(user)
# An item is viewable if:
# 1. There are no permissions set
(!self.blocking_enabled? && !self.targeting_enabled?) ||
# 2. OR the user owns the item
(self.user_id == user.id) ||
# 3. OR the item is not blocked from the user
// Attempt to make a drop-and-forget bunch of scripts that mimick some missing html5 goodies automatically
// Example:
// $(document).ready(function() {
// ProvideHtml5.autofocus()
// ProvideHtml5.datepicker()
// ProvideHtml5.forcenumber()
// })
var ProvideHtml5 = {
autofocus = function() {