Skip to content

Instantly share code, notes, and snippets.

View jaryl's full-sized avatar
🤓
Indie hacking

Jaryl Sim jaryl

🤓
Indie hacking
View GitHub Profile
@jaryl
jaryl / generators.rb
Last active August 9, 2024 09:22
Sample generators.rb file for rails apps
Rails.application.config.generators do |generate|
# generate.assets true # create assets when generating a scaffold
# generate.force_plural false # allow pluralized model names
# generate.helper true # generate helpers
# generate.integration_tool :test_unit # which tool generates integration tests (might be overwritten automatically if using rspec-rails)
# generate.system_tests :test_unit # which tool generates system tests (might be overwritten automatically if using rspec-rails)
# generate.orm false # which orm to use (false uses Active Record)
# generate.resource_controller :controller # which generator generates a controller when using bin/rails generate resource
# generate.resource_route true # generate a resource route definition
# generate.scaffold_controller :scaffold_controller # which generator generates a controller when using bin/rails generate scaffold
@jaryl
jaryl / PicoWSDFatTinyUSB.ino
Created January 2, 2024 03:26
Mount TinyUSB mass storage device using an SD card on a Pico W via SPI
#include <SdFat.h>
#include <Adafruit_TinyUSB.h>
const int _CS = 17;
#define SD_CONFIG SdSpiConfig(_CS, DEDICATED_SPI, SD_SCK_MHZ(12)) // max 50, but may result in read/write errors
Adafruit_USBD_MSC usb_msc;
SdFat sd;
pragma solidity ^0.4.23;
contract NameAddressTranslator {
mapping(bytes32 => address) nameRegistry;
mapping(address => string) addressRegistry;
function toName(address _address) public view returns (string) {
return addressRegistry[_address];
}
@jaryl
jaryl / keybase.md
Created April 15, 2018 10:26
keybase.md

Keybase proof

I hereby claim:

  • I am jaryl on github.
  • I am jaryl (https://keybase.io/jaryl) on keybase.
  • I have a public key ASAEmvpBJNc3SpdZ04BOHSFy9PPi5yQTpw85zzjOOw5X8Qo

To claim this, I am signing this object:

@jaryl
jaryl / large_hadron_concatenator.rb
Last active July 1, 2016 03:55
Code Challenge Solution
DATA = {
[47, 2, 3, 8] => '84732',
[47, 40, 4] => '47440',
[42, 40, 4] => '44240',
[421, 42, 423] => '42423421',
[47, 2, 3, 8, 47, 40, 4, 42, 40, 4, 421, 42, 423] => '84747444242423421404032'
}
def large_hadron_concatenator(data)
data.sort { |a, b| "#{b}#{a}" <=> "#{a}#{b}" }.join
@jaryl
jaryl / spec_helper.rb
Created September 13, 2013 18:53
SpecHelper configuration for sending coverage reports to Coveralls and CodeClimate.
require 'codeclimate-test-reporter'
require 'simplecov'
require 'coveralls'
formatters = [SimpleCov::Formatter::HTMLFormatter]
formatters << Coveralls::SimpleCov::Formatter if ENV['COVERALLS_REPO_TOKEN']
formatters << CodeClimate::TestReporter::Formatter if ENV['CODECLIMATE_REPO_TOKEN']
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[*formatters]
@jaryl
jaryl / bootstrap_form_builder.rb
Created June 28, 2012 08:04 — forked from shamil614/bootstrap_form_builder.rb
Twitter Bootstrap 2.0 Form Builder & Devise
class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
delegate :capture, :content_tag, :tag, to: :@template
%w[text_field text_area password_field collection_select email_field].each do |method_name|
define_method(method_name) do |name, *args|
errors = object.errors[name].any?? " error" : ""
error_msg = object.errors[name].any?? content_tag(:span, object.errors[name].join(","), class: "help-inline") : ""
content_tag :div, class: "control-group#{errors}" do
@jaryl
jaryl / chosen.rb
Created February 6, 2012 08:56 — forked from thijsc/gist:1391107
Select item from chosen js select with Capybara-Webkit
def select_from_chosen(item_text, options)
field_id = find_field(options[:from])[:id]
within "##{field_id}_chzn" do
find('a.chzn-single').click
input = find("div.chzn-search input")
item_text.each_char do |char|
input.base.invoke('keypress', false, false, false, false, char.ord, nil);
end
find('ul.chzn-results').click
input.base.invoke('keypress', false, false, false, false, 40, nil); # down arrow
@jaryl
jaryl / template.rb
Created December 9, 2011 18:11
Rails 3.1 Templater
# set up git and perform initial commit
git :init
append_file '.gitignore' do
<<-EOS
*.rbc
*.sassc
.sass-cache
@jaryl
jaryl / .base_profile
Created July 6, 2011 06:03
Configuration files
SSH_ENV="$HOME/.ssh/environment"
function start_agent {
echo "Initializing new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add;