Skip to content

Instantly share code, notes, and snippets.

View Polyrhythm's full-sized avatar
🎯
Focusing

Polyrhythm

🎯
Focusing
View GitHub Profile
@Polyrhythm
Polyrhythm / C to F converter
Created March 16, 2012 17:53
Ruby C to F converter
print "Hello. Please enter a celsius value: "
celsius = gets
fahrenheit = (celsius.to_i * 9 / 5) + 32
print "The fahrenheit equivalent is: "
print fahrenheit
puts "."
# REFACTORED METHOD (denser, but less readable)
# print "Hello. Please enter a celsius value: "
# print "The fahrenheit equivalent is: " gets.to_i * 9/5 + 32, ".\n"
@Polyrhythm
Polyrhythm / ruby_kickstart 2:4
Created March 30, 2012 17:11
Ruby Array Select example
# Write a method named get_squares that takes an array of numbers
# and returns a sorted array containing only the numbers whose square is also in the array
#
# get_squares [9] # => []
# get_squares [9,3] # => [3]
# get_squares [9,3,81] # => [3, 9]
# get_squares [25, 4, 9, 6, 50, 16, 5] # => [4, 5]
def get_squares(array)
to_return = array.select do |square|
@Polyrhythm
Polyrhythm / Factorial tail call
Created October 3, 2012 05:14
Factorial function with tail call
let rec factorial acc n = match n with
| 0 -> acc
| n -> factorial (n * acc) (n-1)
let factorial_res = factorial 1 6
'use strict';
var lrSnippet = require('grunt-contrib-livereload/lib/utils').livereloadSnippet;
var mountFolder = function (connect, dir) {
return connect.static(require('path').resolve(dir));
};
var path = require('path');
module.exports = function (grunt) {
// load all grunt tasks
@Polyrhythm
Polyrhythm / gist:5707783
Created June 4, 2013 17:20
Express/backbone routing
module.exports = (app) ->
# request specific user
app.get '/users/:user', (req, res) ->
console.log req.params.user
# catch-all for allowing Backbone to handle routing
app.get '*', (req, res) ->
res.render 'app/index'
var style = document.createElement('style');
style.textContent = '@import "' + url + '"';
var fi = setInterval(function() {
try {
style.sheet.cssRules; // <--- MAGIC: only populated when file is loaded
CSSDone('listening to @import-ed cssRules');
clearInterval(fi);
} catch (e){}
}, 10);
counterVal = 4
tick() ->
if counterVal !== 1
# logic each countdown tick
counterVal--
setTimeout tick, 1000
else
# breaking case - callback on countdown completion
@Polyrhythm
Polyrhythm / gist:10184363
Created April 8, 2014 20:15
I want callbacks
var vi = new versalInterface();
var Gadget = function() {
var createListeners = function() {
vi.on('attached', this.render());
// I just want to set a general re-render listener when config changes
vi.on('attributesChanged', function(data) {
for (var key in data) {
this.config[key] = data[key];
{
"id": "5ub4tb",
"title": "Intro to doge",
"isEditable": false,
"shortDesc": "Instructional course on doge",
"longDesc": "This is a course about doge",
"authorBio": "Doges only.",
"tags": [
"amaze",
"wow",
ugh = null
onAdd = (tokenAry) ->
ugh.setProps tokens: tokenAry
component = TokenTextArea({ onAdd: onAdd, tokens: [] })
ugh = React.renderComponent component, $('#component')[0]