Skip to content

Instantly share code, notes, and snippets.

View jsborjesson's full-sized avatar

Jimmy Börjesson jsborjesson

View GitHub Profile
@jsborjesson
jsborjesson / rails_generate_secret_token.sh
Last active August 29, 2015 13:56
Generates a new secret token in a Rails app
# This oneliner generates a new secret_token.rb file,
# just paste it in your terminal at the root of your project
# and it will take care of the rest.
echo "$(rails r "p Rails.application.class.parent_name" | sed "s/\"//g")::Application.config.secret_token = '$(rake secret)'" > ./config/initializers/secret_token.rb
@jsborjesson
jsborjesson / _flashes.html.erb
Last active August 29, 2015 13:56
Bootstrap 3 flashes in Rails
<% flash.each do |type, message| %>
<div class="<%= bootstrap_flash_class type %>"><%= message %></div>
<% end %>
@jsborjesson
jsborjesson / descriptors.py
Created January 18, 2014 21:38
Python descriptors made easy
import re
from weakref import WeakKeyDictionary
class AdvancedDescriptor(object):
"""
Base class for descriptors, is hard to understand but works for most cases.
from https://www.youtube.com/watch?v=P92z7m-kZpc
"""
def __init__(self, name=None):
@jsborjesson
jsborjesson / rsync-deploy.sh
Last active June 12, 2017 13:49
Deploying a folder via rsync over ssh. This is for deployments from OSX to Linux servers.
#!/bin/bash
# You might have to install a new version of rsync for this to work.
# This is easily done by `brew install rsync` and restarting your terminal.
# To use a file as an exclude-list you can use the option
# --exclude-from='donot-deploy.txt'
# Change these to match your settings
USER_NAME='username'
@jsborjesson
jsborjesson / randomColor.js
Created April 6, 2013 16:16
Random hex color in JS
'#'+(0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6);