Skip to content

Instantly share code, notes, and snippets.

@leandromoreira
leandromoreira / gist:3671392
Created Sep 8, 2012
Use seq instead of empty?
View gist:3671392
(def pack [])
;try to avoid this
(if (not (empty? pack)) (print "something") (print "empty"))
;in favor of this
(if (seq pack) (print "something") (print "empty"))
@leandromoreira
leandromoreira / do_something_all_subdirectoreis.sh
Created Oct 22, 2012
Do something in all subdirectories Unix Shell Terminal Command
View do_something_all_subdirectoreis.sh
$ for dir in *; do echo $dir ; done;
View robot.js
var Robot = function(robot) {
};
var firstTime = true;
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
var moveAhead = Math.floor(Math.random()*101);
robot.ahead(moveAhead);
View angular_factory.js
angular.module('twitter')
.factory('theirTwitterFactory', function($http){
var factory = {};
$http.get('/data/theirs.json')
.success(function(data, status, headers, config) {
factory.tweets = data;
});
return {
tweets: function(){
@leandromoreira
leandromoreira / disk_usage.sh
Created Jul 16, 2013
cd / && sudo du -aH --max-depth=1
View disk_usage.sh
cd / && sudo du -aH --max-depth=1
@leandromoreira
leandromoreira / gist:6024640
Created Jul 17, 2013
framebuffer xvfb run tests headless (sweet reminder)
View gist:6024640
/usr/bin/Xvfb :99 -ac -screen 0 1024x768x16
View angular-timeout.html
<!doctype html>
<html ng-app="myApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
</head>
<body>
<div ng-controller="TodoCtrl">
<button ng-click="beQuickOrBeDead()">Fetch with 100ms timeout</button>
<button ng-click="neverEndingStory()">Fetch with default timeout</button>
View example.js
//my initial config
app.config(["$routeProvider", function($routeProvider){
$routeProvider
.when('/list_streams', {
templateUrl: 'assets/angular/views/target_bitrates.html',
controller: 'TargetBitratesCtrl'
})
.when('/transmissions',{
templateUrl: 'assets/angular/views/create_live_media.html',
View service.js
angular.module('Sauron')
.factory('TargetBitrates', ["$http", "$timeout", "Config", function($http, $timeout, Config){
var data = {list: []};
var onSuccess = function(result){
data.list = result.data.data;
$timeout(poller, Config.pollingTimeout);
};
var poller = function() {
$http.get('/streams.json', Config.httpOptions).then(onSuccess);
};
@leandromoreira
leandromoreira / songs.js
Created Aug 7, 2013
Example of testing angular (angularjs) factory using http.
View songs.js
angular.module('pearlJam')
.factory('Songs', function($http, $timeout, Config){
var response = {list: []};
var onSuccess = function(result){
response.list = result.data.data;
$timeout(poller, Config.pollingTimeout);
};
var poller = function(){
$http.get('api/songs.json', Config.httpOptions).then(onSuccess);