Skip to content

Instantly share code, notes, and snippets.

View theCrab's full-sized avatar
💭
What happens when you take a long holiday from work? Shit happens

The Crab theCrab

💭
What happens when you take a long holiday from work? Shit happens
View GitHub Profile
@theCrab
theCrab / ruby-2.3.0.rb
Created May 3, 2017 22:24 — forked from fightingtheboss/ruby-2.3.0.rb
Examples of new features in Ruby 2.3.0
# These are examples of new features in Ruby 2.3.0
#---------------------------------------------------------------------------
## Did You Mean?
"Typos suck less now".revers
# NoMethodError: undefined method `revers' for "Typos suck less now":String
# Did you mean? reverse
# reverse!
@theCrab
theCrab / ola.js
Last active February 4, 2017 16:08
Ola's Loop
var array = []
var emptyValuesArray = []
var hash = { a: 1, b: 1, c: 1, d: 1, e: null, f: null }
forEach( h in hash) {
// Loop through each element inside the hash variable above
// if the value is null or empty ('') i.e true,
// add the h to the array, if false add to emptyValuesArray
if (h.value === null || ha.value === '') { // Check if h.value is empty or null. Returns true/false
array.push(h)
@theCrab
theCrab / CustomSegmentedControl.m
Last active November 22, 2016 17:57
Customise UISegmentedCotrol. This code is translated from Swift 3 to Objective-C
//
// SpotaSegmentedController.m
// Spota
//
// Created by The Crab on 19/11/2016.
// Use this code as you please. This is a port from Swift 2.
// Original by: http://www.appdesignvault.com/custom-segmented-control-swift-tutorial/
// Copyright © 2016 The Crab. All rights reserved.
//
@theCrab
theCrab / map_layout.rb
Created November 22, 2016 09:50
ProMotion-map and MotionKit as root view
# MapLayout
class MapLayout < MK::Layout
# view :info_container
# view :info_image
# view :info_label
#
# view :settings_container
# view :settings_segmented_control
def layout
@theCrab
theCrab / rename.sh
Created September 26, 2016 17:51
UNIX Rename files in a multi level folder structure
for file in ./sass/_*.scss; do
mv $file ${file//[_]}.scss # remove all underscores '_'
done
@theCrab
theCrab / Rakefile
Created April 28, 2016 16:46 — forked from dblandin/Rakefile
RubyMotion Configuration and Deploy/Release
# -*- coding: utf-8 -*-
$:.unshift('/Library/RubyMotion/lib')
require 'motion/project/template/ios'
require 'bundler'
Dir.glob('./config/*.rb').each { |file| require file }
if ARGV.join(' ') =~ /spec/
Bundler.require :default, :development, :spec
elsif ARGV.join(' ') =~ /testflight/
@theCrab
theCrab / authentication.rb
Last active April 27, 2022 15:42
A Hanami Framework authentication based on JSON Web Tokens.
# lib/authentications/authentication.rb
# @api auth
# Authentication base class
#
module Authentication
def self.included(base)
base.class_eval do
before :authenticate!
expose :current_user
@theCrab
theCrab / lotusrb-testing.markdown
Last active August 29, 2015 14:27
Step by Step testing a LotusRB App

Introduction:

In the past weeks I bumped into LotusRB from my RubyWeekly.com newsletter published by @PeterC, signup if you haven't (pun intended). After a few glances I fell in love. So i immediately setout to get my next project at work going. Lotus is very testable. And as usual in the Ruby world, there is enough rope to kill 10 newbies in one go. After a bit of enthusiasm came the realization that i'd better do things the right way and make my life easy.

Testing:

There are things to test. Depending on how you like your flow. Lotus supports both MiniTest by default and RSpec as an option. Just follow the 'get started' docs and get your app going.

BDD can easily be done without hitting the DB. Capybara is included and a spec/web/features directory is a start for you. So, assuming you are a Lotus newbie. You might want to know what you need to test.

@theCrab
theCrab / puma.rb
Last active August 29, 2015 14:26 — forked from yamaaki/puma.rb
# Start Puma with next command:
# RAILS_ENV=production bundle exec puma -C ./config/puma.rb
# uncomment and customize to run in non-root path
# note that config/puma.yml web path should also be changed
application_path = "#{File.expand_path("../..", __FILE__)}"
# The directory to operate out of.
#
# The default is the current directory.
@theCrab
theCrab / datamapper-github-acl-example.rb
Created January 30, 2014 22:09
How to implement the GitHub Orgs, Users, Repo Access Control Level using DataMapper.
class Organisation
include DataMapper::Resource
property :id, Serial
property :name, String, length: 3..15
timestamps :created_at, :updated_at
belongs_to :user
has n, :teams