Skip to content

Instantly share code, notes, and snippets.

View nakajima's full-sized avatar
💭
you can have statuses now?

Pat Nakajima nakajima

💭
you can have statuses now?
View GitHub Profile
@nakajima
nakajima / blend mode playground.swift
Created July 29, 2023 08:11
blendmode playground
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
@State private var mode: BlendMode = .normal
let cases: [BlendMode] = [
.normal,
.multiply,
.screen,
@nakajima
nakajima / sinatra-auth.rb
Created October 13, 2008 01:12
Easy basic auth for Sinatra actions
=begin
Easy Basic Authentication for Sinatra actions.
USAGE
require 'rubygems'
require 'sinatra'
require 'sinatra-auth'
module Operations
def self.list
@list ||= []
end
class Base
def self.inherited(klass)
Operations.list << klass
end
@nakajima
nakajima / interpolate.js
Created March 8, 2011 19:04
javascript string interpolation
String.prototype.interpolate = function(object) {
return this.replace(/#{([\w0-9]+)}/g, function(val, match) {
return object[match];
})
}
String.prototype.evilInterpolate = function() {
return this.replace(/#{([\w0-9]+)}/g, function(val, match) {
return eval(match);
});
@nakajima
nakajima / FIRST
Created May 27, 2009 01:05
Guide on how to invoke a method in Ruby.
Here's an example of a few different ways to call a method on a Ruby object.
If you're a beginner, try running the code above to watch it in action.
If you're not a beginner, go ahead and tear me a new one for whichever techniques I forgot ;)
- Pat
@nakajima
nakajima / hp
Created January 18, 2011 18:38
heroku production command wrapper thing
#!/usr/bin/env ruby
require 'readline'
loop do
command = Readline.readline('> ')
command == "exit" && exit
puts "heroku #{command} --remote production"
system("heroku #{command} --remote production")
end
[~/.js] cat github.com.js
// Hashtagify emoji
$(function() {
$('img.emoji').each(function() {
var name = $(this).attr("title").replace(/:/g, '')
if (name == '+1') { name = "thumbsup" }
if (name == '-1') { name = "thumbsdown" }
hashtag = $("<span>#" + name + "</span>");
hashtag.css({ color: '#000', fontWeight: 'bold' });
$(this).replaceWith(hashtag)
@nakajima
nakajima / launchpad-art.rb
Last active December 16, 2015 00:59
Draw crap on your Novation Launchpad. You'll need the unimidi gem. You know where to get it.
# USAGE
#
# Make sure your launchpad is plugged in.
#
# $ ruby launchpad-art.rb
#
# Select your launchpad from the list of midi controllers, then start pushing
# buttons on your launchpad.
require "unimidi"
// Speaker Clicker
int maxIndicatorPin = 1;
int okayIndicatorPin = 2;
int speakerPin = 13;
int pitchPin = 0;
int pitch = 750;
void setup() {
pinMode(speakerPin, OUTPUT);
@nakajima
nakajima / uʍop ǝpısdn.rb
Created February 10, 2012 00:05
this is why we pair
def sʇnd
:PUTS
end
BINDING = binding
class << self
define_method :method_missing do |sym, *args|
value = eval(sym.to_s, BINDING)
puts value