Skip to content

Instantly share code, notes, and snippets.

@utgarda
utgarda / reverse.coffee
Created March 22, 2012 12:25 — forked from Chris927/reverse.coffee
Reverse a string in CoffeeScript
reverse = (s) ->
if s.length < 2 then s else reverse(s[1..-1]) + s[0]
s = "Hello"
console.log "s=#{s}, s.reverse=#{reverse(s)}"
@utgarda
utgarda / LinkedInClient.coffee
Created March 3, 2012 16:42 — forked from brikis98/LinkedInClient.coffee
LinkedIn API Client in CoffeeScript
OAuth = require('oauth').OAuth
_ = require 'underscore'
class LinkedInClient
@baseUrl: 'https://api.linkedin.com'
@requestTokenUrl: "#{@baseUrl}/uas/oauth/requestToken"
@accessTokenUrl: "#{@baseUrl}/uas/oauth/accessToken"
@authorizeUrl: "#{@baseUrl}/uas/oauth/authorize"
@profileFields: ['id', 'headline', 'first-name', 'last-name', 'public-profile-url', 'picture-url', 'educations', 'positions', 'email-address']
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>SoundCloud OAuth 2 User Agent Authentication Flow Demo</title>
<script type="text/javascript" charset="utf-8" src="javascript/jquery-1.4.2.js"></script>
<script type="text/javascript" charset="utf-8">
$(function () {
var extractToken = function(hash) {
@utgarda
utgarda / README.md
Created January 16, 2012 05:10
CoffeeScript + jQuery tutorials

CoffeeQuery

CoffeeScript + jQuery tutorials

  • Various jQuery tutorials ported to CS
  • CoffeeScript basics
  • Cool colours, not the least of features :)
@utgarda
utgarda / ani.stack.1.coffee
Created January 13, 2012 15:56
CoffeeScript + jQuery tutorials: Stacking animations http://coffeequery.blogspot.com
$j = jQuery
$j('#ani2_btn1').click ->
$j('#ani2_worm_bar')
.animate(width:78).animate(left:'+=40',width:38)
@utgarda
utgarda / jquery_animation_1.2.html
Created January 12, 2012 16:40
jQuery + CoffeeScript tutorial: animation stacking http://coffeequery.blogspot.com/
<!DOCTYPE html>
<html>
<head>
<title>jQuery + CoffeeScript tutorial: animation stacking</title>
<style>
div.tree-frog {font-size: 12pt; border: 1px solid white; height: 38px; width: 38px; position: absolute}
</style>
<script src="coffee-script.js"></script>
<script src="jquery-1.7.1.js"></script>
</head>
<div id="palette" style="width: 510px; height: 80px;">
</div>
<script type="text/coffeescript">
colors = ['#CCDDBB', '#99CC66', '#88AA66', '#AADDCC', '#66AAAA', '#559999', '#FFFFDD', '#FF9922', '#DD8822', '#AACCDD', '#5599CC', '#4477AA']
next_square_html = (color) ->
"""
<div style="background: #{color};
border: 1px solid grey;
height: 30px;
@utgarda
utgarda / jquery_animation_1.coffee
Created January 2, 2012 20:55
CoffeeScript + jQuery animation example http://coffeequery.blogspot.com
#Using $j instead of just $ to be more specific
$j = jQuery
#Storing page elements to local variables
clickme = $j '#ani1_clickme'
restore = $j '#ani1_restore'
bar1 = $j '#ani1_bar1'
bar2 = $j '#ani1_bar2'
#Cool shortcut, instead of $j(document).ready(function(){
major, minor = `bison --version`.scan(/bison \(GNU Bison\) (\d+)\.(\d+)/)[0].map(&:to_i)
$?.exitstatus == 0 && ([major, minor] <=> [2,4]) >=0
@utgarda
utgarda / ring_benchmark.erl
Created December 8, 2010 16:51
Tutorial problem from "Programming Erlang" by Joe Armstrong , 8.11 Write a ring benchmark. Create N processes in a ring. Send a msage round the ring M times so that a total of N * M messages sent. Time how long this takes for different values of N and M.
-module(ring_benchmark).
-export([new/2]).
new(N, M) ->
spawn(fun() -> spawn_ring(N, M) end).
spawn_ring(N, M) ->
io:format("First process: ~p~n", [self()]),
NextPid = spawn_rest(self(), N),