Skip to content

Instantly share code, notes, and snippets.

View hernan's full-sized avatar

Hernan Fernandez hernan

  • Argentina
View GitHub Profile
@hernan
hernan / main.js
Created July 29, 2014 17:32 — forked from nirleka/main.js
//courtesy: http://victorblog.com/2012/12/20/make-angularjs-http-service-behave-like-jquery-ajax/
angular.module('session', ['$strap.directives'], setPostHeader)
//angular def (router, run ect
/**
* Set default header AJAX Angular agar bisa dibaca oleh PHP lewat POST
* @param $httpProvider
*/
function setPostHeader($httpProvider) {
class API::V1::BaseController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
/* ---------------------------------------------------------- */
/* */
/* A media query that captures: */
/* */
/* - Retina iOS devices */
/* - Retina Macs running Safari */
/* - High DPI Windows PCs running IE 8 and above */
/* - Low DPI Windows PCs running IE, zoomed in */
/* - Low DPI Windows PCs and Macs running Firefox, zoomed in */
/* - Android hdpi devices and above */
var movementHistory = {
pointAndTimeHistory: [],
set: function(point) {
// add this point into the point and time history for velocity calculations based on time & distance
this.pointAndTimeHistory.push({
time: new Date().getTime(),
x: point.x,
y: point.y
});
@hernan
hernan / app.js
Created February 23, 2014 23:00 — forked from dawsontoth/app.js
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
/**
* Adds "swipe" event support to Android, and adds swipe up and down to iOS.
* @param view The view that should be made swipeable.
* @param allowVertical Whether or not vertical swipes (up and down) are allowed; default is false.
* @param tolerance How much further you need to go in a particular direction before swipe is fired; default is 2.
*/
function makeSwipeable(view, allowVertical, tolerance) {
tolerance = tolerance || 2;

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@hernan
hernan / round_down.rb
Last active December 18, 2015 09:28
round down a float
class Float
def round_down n=0
s = self.to_s
l = s.index('.') + 1 + n
s.length <= l ? self : s[0,l].to_f
end
end
# 2nd variant
class Float
# Rake task to launch multiple Resque workers in development/production with simple management included
require 'resque/tasks' # Require Resque tasks
namespace :workers do
# = $ rake workers:start
#
# Launch multiple Resque workers with the Rails environment loaded,
# so they have access to your models, etc.