Skip to content

Instantly share code, notes, and snippets.

@Davidslv
Davidslv / repeatme
Last active December 4, 2015 14:49
Bash function to repeat anything in the terminal
# usage: repeatme 3 "echo e"
function repeatme() {
for i in $(seq 1 $1) ; do
$2
done
}
@Davidslv
Davidslv / timez.rb
Created April 29, 2015 14:32
Having fun with times
Failure/Error: expect(resource_time.to_time).to eq Time.now
expected: 2015-04-29 15:23:34 +0100
got: 2015-04-29 15:23:34 +0100
# Solution:
expect(resource_time.to_s).to eq Time.now.utc.to_s
@Davidslv
Davidslv / super_service_object.rb
Last active August 29, 2015 14:13
how to speed up your workers?
class SuperServiceObject
attr_reader :user, :options
def new(user_id, options = {})
@user = User.find(user_id)
@options = options
end
def call
# move the code here
/* Exercise: Loops and Functions #43 */
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := float64(2.)
https://github.com/bbatsov/rubocop#atom
https://github.com/yujinakayama/atom-lint
https://github.com/AtomLinter/linter-rubocop
https://github.com/AtomLinter/Linter
@Davidslv
Davidslv / git-clean-branch.md
Last active August 29, 2015 13:57
Remove merged branches from local repo

If you want to do some housekeeping locally and want to remove branches that have been merged, checkout master and then:

git branch --merged | grep -v "\*" | xargs -n 1 git branch -d
@Davidslv
Davidslv / fact.erl
Created February 5, 2014 20:11
Factorial function in erlang
-module(fact).
-export([factorial/1]).
%% The solution is tail recursive
factorial(N) ->
factorial(1, N, 1).
factorial(Current, N, Result) when Current =< N ->
NewResult = Result * Current,
@Davidslv
Davidslv / browsers.js
Created February 3, 2014 08:14
jQuery bad code for browser detection
// Bad Code from Efytimes:
// http://efytimes.com/e1/fullnews.asp?edid=128774
// Please don't use this code in your website if you have jQuery > 1.9
$(document).ready(function() {
// If the browser type if Mozilla Firefox
if ($.browser.mozilla && $.browser.version >= "1.8" ){
// some code
}
// If the browser type is Opera
@Davidslv
Davidslv / .railsrc
Created October 14, 2013 16:30
railsrc
#!/usr/bin/env ruby
# show queries
def logs_on
if defined?(ActiveRecord)
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.clear_reloadable_connections!
"Logs on!"
end
end
@Davidslv
Davidslv / .irbrc
Created October 14, 2013 16:29
irbrc
#!/usr/bin/env ruby
def r!
reload!
end
if ENV['RAILS_ENV']
load "#{ENV['HOME']}/.railsrc"
end