Skip to content

Instantly share code, notes, and snippets.

View Rafailong's full-sized avatar
🤠

ravila Rafailong

🤠
  • Mexico
View GitHub Profile
@Rafailong
Rafailong / script.scala
Created March 9, 2017 23:57
Usergrid Java SDK Retrieving Counter
private def retrieveCounters(counter: String): Unit = {
val usergridBaseURL = Usergrid.getInstance().clientAppUrl() // https://api.usergrid.com/my-org/my-app
val url = s"$usergridBaseURL/counters?counter=$counter"
val request = new UsergridRequest(UsergridHttpMethod.GET, UsergridRequest.APPLICATION_JSON_MEDIA_TYPE, url, Usergrid.authForRequests())
val result = Usergrid.sendRequest(request)
println(result.getStatusCode, result.getResponseError.getErrorDescription)
}
@Rafailong
Rafailong / unique.js
Created January 26, 2017 19:39
unique based on reduce
var rr = [1,2,3,1,3,4,5];
var r = rr.reduce(function (acc, current) {
return acc.indexOf(current) < 0 ? acc.concat(current) : acc;
}, []);
// r = [1, 2, 3, 4, 5]
'use strict';
function task(number) {
var r = 0;
for (var i = 0; i < number; i++) {
var frac = 1 / ((3 * i) + 1);
r = r + frac;
}
@Rafailong
Rafailong / index.js
Created December 10, 2015 04:44
Y-Combinator
var Y = require('./y');
function factorial(proc) {
return function (n) {
return n === 0 ? 1 : (n * proc(n - 1));
}
}
var fact = Y(factorial);
var r = fact(3);
console.log(r);
@Rafailong
Rafailong / docker-cleaner.sh
Created October 22, 2015 16:56
Docker remove commands
#! /bin/bash
# remove all stoped container
docker rm $(docker ps -a -q)
# remove tagged images
docker rmi $(docker images -q)
# remove untagged images
docker rmi $(docker images | grep "^<none>" | awk "{print $3}"
@Rafailong
Rafailong / commit-msg.rb
Last active August 29, 2015 14:08
git hook to log time entry in redmine when committing to git, remember to remove the file extension, this MUST be executable
#!/usr/bin/env ruby
require 'rubygems'
require 'rest_client'
require 'json'
url = 'http://yourredmine.com/time_entries.xml'
api_key = "your-redmine-api-key"
activity_id = 'your development activity id'
commitMessage = ARGV[0]
using System;
using JabbR.Infrastructure;
using JabbR.Models;
using JabbR.Services;
using Nancy;
using Nancy.Authentication.WorldDomination;
using WorldDomination.Web.Authentication;
namespace JabbR.Nancy
{
// api/controllers/AuthController.js
var passport = require('passport');
var AuthController = {
login: function (req,res)
{
res.view();
},
@Rafailong
Rafailong / script.js
Created January 29, 2014 18:32
Sort a list alphabetically
$(function() {
$.fn.sortList = function() {
var mylist = $(this);
var listitems = $('li', mylist).get();
listitems.sort(function(a, b) {
var compA = $(a).text().toUpperCase();
var compB = $(b).text().toUpperCase();
return (compA < compB) ? -1 : 1;
});
$.each(listitems, function(i, itm) {
@Rafailong
Rafailong / script.js
Created January 29, 2014 18:31
Check if an image is loaded
var imgsrc = 'img/image1.png';
$('<img/>').load(function () {
alert('image loaded');
}).error(function () {
alert('error loading image');
}).attr('src', imgsrc);