Skip to content

Instantly share code, notes, and snippets.

@Tmw
Tmw / gist:fa18019595a36e3f190a
Last active August 29, 2015 14:24
Combining multiple Active_Model_Serializers in one output
class PersonSerializer < ActiveModel::Serializer
attributes :first_name, :last_name
def attributes
super.merge(AddressSerializer.new(object.address).serializable_hash)
end
end
# Given a model Person with an association has_one Address
# The example above will serialize to:
# {
@Tmw
Tmw / BAM.ino
Created May 9, 2015 17:18
Bit Angle Modulation, Arduino and Shift Registers
#include <SPI.h>
// define pins and other variables
const int latchPin = 8;
const int clockPin = 13;
const int dataPin = 11;
const int NUMBER_OF_CONNECTED_LEDS = 16;
// global array that keeps track of the LEDs brightnesses
bool brightnessMask[NUMBER_OF_CONNECTED_LEDS*4];
@Tmw
Tmw / BAM.ino
Last active August 29, 2015 14:20
Basic Bit Angle Modulation using Arduino and 595 shift registers
#include <SPI.h>
// define pins and other variables
const int latchPin = 8;
const int clockPin = 13;
const int dataPin = 11;
const int NUMBER_OF_CONNECTED_LEDS = 16;
// global array that keeps track of the LEDs brightnesses
bool brightnessMask[NUMBER_OF_CONNECTED_LEDS*4];
@Tmw
Tmw / gist:0c61600fc4821e85bce5
Created March 17, 2015 13:35
Dockerfile - nodejs
FROM node:0.12
# replace this with your application's default port
EXPOSE 4000
RUN mkdir /src
VOLUME /src
WORKDIR /src
CMD ["npm", "install"]
@Tmw
Tmw / basics-arduino-spi
Created March 14, 2015 16:48
Getting started with Arduino and SPI.h
#include <SPI.h>
// define pins and other variables
const int latchPin = 8;
const int clockPin = 13;
const int dataPin = 11;
// setup the correct pins and initialize SPI library
void setup() {
// setup pins
@Tmw
Tmw / sidekiq.config
Created February 4, 2015 10:35
Setup Sidekiq on AWS EB with Ruby 2.1 (Amazon Linux 2014.09 v1.0.9)
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/50_restart_sidekiq":
mode: "000777"
owner: root
group: root
content: |
cd /var/app/current
mkdir -p /var/app/current/tmp/pids
mkdir -p /var/app/current/tmp/logs
@Tmw
Tmw / react-calculator.html
Last active August 29, 2016 17:56
Poorly written calculator in React.js + JSX
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Another React.js experiment (with JSX)</title>
<script src="http://fb.me/react-with-addons-0.10.0.js"></script>
<script src="http://fb.me/JSXTransformer-0.10.0.js"></script>
</head>
@Tmw
Tmw / react-js-codelock.html
Last active August 29, 2015 13:58
Tiny codelock built with React.js
<!DOCTYPE html>
<html>
<head>
<script src="//fb.me/react-0.9.0.js"></script>
<meta charset="utf-8">
<title>Little code lock in React.js</title>
</head>
<body>
<script>
@Tmw
Tmw / gulpfile.js
Created April 4, 2014 12:24
Gulpfile that lists changes/renames/removals
var gulp = require('gulp');
gulp.task('default', function(){
var watcher = gulp.watch('*.txt');
watcher.on('change', function(event){
console.log('Something happened: ', event);
});
});
@Tmw
Tmw / Companies_controller.php
Created November 17, 2011 09:10
Overview of our companies controller
<?php
class CompaniesController extends AppController {
function index(){
$companies = $this->Company->find('all', array('limit' => 10));
$this->set('companies', $companies);
$this->loadModel('Category');
$categories = $this->Category->find('all');
$this->set('categories', $categories);