Skip to content

Instantly share code, notes, and snippets.

@yitznewton
yitznewton / struct.php
Last active August 29, 2015 14:24
PHP structs (hypothetical)
struct Person {
Age $age;
Address $address;
HairColor $hairColor;
Length $height?; // optional? not sure if worth it
}
$yitz = Person(
$age => new Age(30),
$address => $someAddress,
@yitznewton
yitznewton / starbucks_map.html
Last active August 19, 2022 08:44
Starbucks Stores API / Google Maps JS API mashup with browser geolocation
<html>
<head></head>
<body>
<div id="map-canvas" style="height: 600px; width: 600px;"></div>
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_GOOGLE_MAPS_API_KEY_HERE"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
var positionToStarbucksLatlng = function(position) {
@yitznewton
yitznewton / pascal.scm
Last active August 29, 2015 14:14
Pascal's Triangle
(define (pascal row col)
(define (row_underflow? col) (< col 0))
(define (row_overflow? row col) (> col row))
(define (initial_cell? row) (= row 0))
(cond
((row_underflow? col) 0)
((row_overflow? row col) 0)
((initial_cell? row) 1)
(else
@yitznewton
yitznewton / mixins.rb
Created January 14, 2015 14:54
Mixins: good and evil
# evil
module MoarMethods
def foo
end
def bar
end
end
@yitznewton
yitznewton / github_issue_titles.css
Created October 31, 2014 14:53
Expand GitHub issue titles in comments (Stylish)
.issue-link[title]:after {
content:attr(title);
font-size: 0.8em;
margin-left: 0.4em;
margin-right: 0.6em;
padding: 0.2em 0.4em;
border: 1px solid #ccc;
background: #eee;
color: #777;
position: relative;
@yitznewton
yitznewton / .bash_profile
Last active August 29, 2015 14:08
Bash profile
function git_checkout
{
REF=$(git symbolic-ref HEAD 2> /dev/null)
HASH=$(git rev-parse --short HEAD 2> /dev/null) || return
if [ -n "$REF" ] ; then echo "("${REF#refs/heads/}") " ;
elif [ -n "$HASH" ] ; then echo "("${HASH}") " ;
fi
}
@yitznewton
yitznewton / mac_rbenv.sh
Last active August 29, 2015 14:08
Installing Ruby on Mac with rbenv
brew install rbenv rbenv-gemset rbenv-bundler ruby-build
# add $HOME/.rbenv/bin to $PATH
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile # to enable shims and auto-complete
rbenv install ruby-2.1.3 # or other desired/current version
# change to your project dir, then:
echo '.gems' > .rbenv-gemsets
rbenv local 2.1.3
gem install bundler
@yitznewton
yitznewton / 0_trelloboard_repository.js
Last active August 29, 2015 14:07
Decoupled domain module in AngularJS
define(function() {
'use strict';
function TrelloboardRepository($q) {
this.$q = $q;
}
TrelloboardRepository.prototype = {
find: function() {
// first iteration: just return a hard-coded Trelloboard
@yitznewton
yitznewton / gist:0dfcc01973158e4cf1d8
Last active August 29, 2015 14:07
PHP pseudo-overload getter/setter
<?php
class Foo
{
private $bar;
public function bar($newBar = null)
{
if ($newBar !== null) {
$this->bar = $newBar;
@yitznewton
yitznewton / api_client_code.php
Last active August 29, 2015 14:07
API client
<?php
function get_projects(ApiClient $api)
{
$projectList = [];
foreach ($api->getProjects(['limit' => 200]) as $project) {
$projectList[$project->getId()] = $project->getData()->name;
}