Skip to content

Instantly share code, notes, and snippets.

View Fintan's full-sized avatar

Fintan Fintan

View GitHub Profile
@Fintan
Fintan / gist:7697b8d1ddde7f01338c
Created June 17, 2014 08:13
Jasmine Spy snippets
var Person = function() {};
Person.prototype.helloSomeone = function(toGreet) {
return this.sayHello() + " " + toGreet;
};
Person.prototype.sayHello = function() {
return "Hello";
};
@Fintan
Fintan / convertToBinary.js
Last active August 29, 2015 14:08
taken from this book on Bytes in Flash http://www.bytearray.org/?p=711
function convertToBinary(numberToConvert, bits)
{
var result = "";
var lsb;
var lng = bits || 32;
for (var i = 0; i < lng; i++) {
// Extract least significant bit using bitwise AND.
lsb = numberToConvert & 1;
// Add this bit to the result.
result = (lsb == 1 ? "1" : "0") + result;
@Fintan
Fintan / selectElement.js
Last active August 29, 2015 14:08
When naming of data attributes are not be standardised this method lets me select the element based on a few possibilities
//naming of filters tends to not be standardised so we need to cover a few possibilities
var _selectElement = function($container, selectorTemplate, name) {
var count = 0;
var template = _.template(selectorTemplate);
var $el;
var nameStr;
var strategies = [
function(str) { return str; },
function(str) {return _.str.capitalize(str.toLowerCase())},
@Fintan
Fintan / BackboneAction.js
Last active August 29, 2015 14:08 — forked from spoike/reflux.js
var Backbone = require('backbone');
exports.createAction = function() {
var action = Backbone.Events,
eventLabel = "action",
functor;
functor = function() {
action.trigger(eventLabel, Array.prototype.slice.call(arguments, 0));
@Fintan
Fintan / gist:c39a643c22219ecbc0ae
Created May 1, 2015 16:27
How many listeners subscribed to a Backbone Event?
//list all events on an event object
Backbone._events
//how many listeners subscribed to a Backbone Event
Backbone._events['customEvent'].length
//The actual event listener methods for an event
Backbone._events['customEvent'].forEach(function(listener) { console.log(listener.callback); } )
@Fintan
Fintan / concurrency_hello.ex
Last active August 29, 2015 14:24
simple example showing concurrency with elixir (based on looking at http://learnxinyminutes.com/docs/elixir/)
# All we need to write concurrent programs in elixir
# are three primitives:
# spawning processes, sending messages and receiving messages.
defmodule GreetingMod do
def hello_world do
receive do
{:your_name, name} ->
IO.puts("Hello, #{name}")
end
@Fintan
Fintan / gist:b7b62c8ef6323db54894
Created July 7, 2015 12:50
closure example in Elixir
iex> add_two = fn a -> add.(a, 2) end
#Function<6.71889879/1 in :erl_eval.expr/5>
iex> add_two.(2)
4
@Fintan
Fintan / Cygwin_Install_and_Config_Instructions.md
Last active December 23, 2015 11:52
Cygwin Install and Config Instructions

Cygwin is a collection of tools that provide a Linux look and feel environment for Windows. If you install it, you can use linux commands and services on Windows.

Install Cygwin: Instructions are here - http://cygwin.com/

Install package manager for cygwin called apt-cyg:

lynx -source rawgit.com/transcode-open/apt-cyg/master/apt-cyg > apt-cyg

#find the number of files in current dir that are older than 6 days
find ./ -type f -mtime +6 | wc -l
#remove files in current dir that are older than 5 days
find ./ -type f -mtime +5 -exec rm {} \;
#find the number of characters in a line
echo "This is my Input" | wc -c
@Fintan
Fintan / TTS.sh
Last active July 27, 2016 18:54
Create voice recordings of text with Ubuntu
#dependencies
sudo apt-get install libttspico-utils
sudo apt-get install ffmpeg
#generate wav from text
pico2wave -w=out.wav -l=en-GB "Hello there"
#convert wav to mp3
ffmpeg -i ./out.wav -b:a 160k -metadata artist=homebrook ./out.mp3 -y