Skip to content

Instantly share code, notes, and snippets.

View jsborjesson's full-sized avatar

Jimmy Börjesson jsborjesson

View GitHub Profile
@jsborjesson
jsborjesson / inline_ruby.vim
Last active August 29, 2015 14:01
Execute selected ruby into inline comments
" Inline ruby interpretation, inspired by RubyTapas.
"
" Example output when run over the top line:
"
" 3.times { |num| puts num }
" # => 0
" # => 1
" # => 2
"
vmap <leader>r :!tee >(cat) \| ruby \| sed 's/^/\\# \=> /'<cr>
@jsborjesson
jsborjesson / ntfs.sh
Created June 11, 2014 18:56
Mount NTFS drive on OSX
# Create or edit /etc/fstab/ to contain this:
LABEL=VOLUME_NAME none ntfs rw,auto,nobrowse
@jsborjesson
jsborjesson / git-remote-rename.sh
Created April 28, 2015 16:10
Recursively updates git remotes when you've renamed an organization
#!/bin/sh
for i in $(find $PWD -maxdepth 1 -type d); do
cd $i
if [ -d .git ]; then
remotes=$(git remote -v)
if [[ "$remotes" =~ origin.git@github.com:myorg ]]; then
git remote set-url origin git@github.com:myneworg/$(basename `git rev-parse --show-toplevel`)
fi
fi
cd ..
def x(one: 1, two: 2)
local_variables.each_with_object({}) do |var, memo| memo[var] = eval(var.to_s) end
end
# This is a place where you can put code that should be executed once,
# and accessed by several different threads. When it is called, it will
# block the thread until the calculation has been completed, and memoize it.
#
# This means all threads that call the same method will wait for the same result,
# that is only carried out once. Think of it as a traffic light; cars arrive at the
# red light at different times, wait, and all take off together once it turns green.
class CrossThreadMemoizer
def initialize(callable)
@callable = callable
@jsborjesson
jsborjesson / tables.css
Created July 7, 2015 07:57
Makes tables look decent
table {
padding: 0;
border-collapse: collapse;
}
table tr {
border-top: 1px solid #cccccc;
background-color: white;
margin: 0;
padding: 0;
@jsborjesson
jsborjesson / sequel_migrations.rb
Last active August 29, 2015 14:25
Rails-like rake db:migrate with sequel
# Rakefile
namespace :db do
desc "Run migrations"
task :migrate, [:version] do |t, args|
require "sequel"
Sequel.extension :migration
db = Sequel.connect(ENV.fetch("DATABASE_URL"))
if args[:version]
puts "Migrating to version #{args[:version]}"
Sequel::Migrator.run(db, "db/migrations", target: args[:version].to_i)
# Reset
Color_Off='\[\e[0m\]'
# Regular Colors
Black='\[\e[0;30m\]'
Red='\[\e[0;31m\]'
Green='\[\e[0;32m\]'
Yellow='\[\e[0;33m\]'
Blue='\[\e[0;34m\]'
Purple='\[\e[0;35m\]'
import java.util.ArrayList;
import java.util.Arrays;
public class Primes {
public static void main(String[] args) {
int limit = 1000;
// Calculate primes under limit and measure the time it took
long startTime = System.currentTimeMillis();
ArrayList<Integer> answer = primes(limit);
@jsborjesson
jsborjesson / rake_remove_task.rb
Created June 16, 2016 12:15
Programatically remove a task by name in Rake
# Monkeypatch to remove tasks
module Rake
def self.remove_task(task_name)
Rake.application.instance_variable_get('@tasks').delete(task_name.to_s)
end
end
# Example: disable all of the tasks in the db namespace
namespace :db do |ns|
ns.tasks.each do |task|