Skip to content

Instantly share code, notes, and snippets.

View guihatano's full-sized avatar
🏠
Working from home

Guilherme Y. Hatano guihatano

🏠
Working from home
View GitHub Profile
@masonjm
masonjm / depends_on.js
Created May 22, 2014 00:43
Show/Hide form fields based on the value in another field.
(function( $ ){
$.fn.dependsOn = function(element, value) {
var elements = this;
var hideOrShow = function() {
var $this = $(this);
var showEm;
if ( $this.is('input[type="checkbox"]') ) {
showEm = $this.is(':checked');
} else if ($this.is('select')) {
@moertel
moertel / suppress_ruby_output.rb
Last active March 21, 2024 08:54
Temporarily suppress STDOUT and STDERR (ruby)
# Temporarily redirects STDOUT and STDERR to /dev/null
# but does print exceptions should there occur any.
# Call as:
# suppress_output { puts 'never printed' }
#
def suppress_output
original_stderr = $stderr.clone
original_stdout = $stdout.clone
$stderr.reopen(File.new('/dev/null', 'w'))
$stdout.reopen(File.new('/dev/null', 'w'))
@shrikanthkr
shrikanthkr / carrierwave-base64.md
Last active September 6, 2019 16:21
Saving base64 string with Carrierwave

In the controller action

image_file = change_img_params(params[:avatar]) #params[:avatar] - base64 string

def change_img_params(img)
begin
  Base64.decode64(img) #To check if thats a base64 string
  if img
    img = file_decode(img.split(',')[1],"some file name") #getting only the string leaving out the data/<format>

end

@anotheruiguy
anotheruiguy / web-fonts-asset-pipeline.md
Last active May 24, 2023 22:08
Custom Web Fonts and the Rails Asset Pipeline

Web fonts are pretty much all the rage. Using a CDN for font libraries, like TypeKit or Google Fonts, will be a great solution for many projects. For others, this is not an option. Especially when you are creating a custom icon library for your project.

Rails and the asset pipeline are great tools, but Rails has yet to get caught up in the custom web font craze.

As with all things Rails, there is more then one way to skin this cat. There is the recommended way, and then there are the other ways.

The recommended way

Here I will show how to update your Rails project so that you can use the asset pipeline appropriately and resource your files using the common Rails convention.

@phollyer
phollyer / spreadsheet_test
Created September 13, 2011 17:43
Spreadsheet Gem - updating an existing sheet without changing the output location or filename
#!/usr/bin/env ruby
require 'spreadsheet'
# Begin Test
print "Spreadsheet Test\n"
# Create the rows to be inserted
row_1 = ['A1', 'B1']
row_2 = ['A2', 'B2']
@gkolok
gkolok / gist:715391
Created November 25, 2010 13:28
simple ruby soap post with basic authentication
require 'net/http'
request_body = <<EOF
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.host/">
<soapenv:Header/>
<soapenv:Body>
<ser:createGroup>
<arg0>
<description>#{description}</description>
<name>#{name}</name>
@mudge
mudge / gist:428455
Created June 7, 2010 09:29
Namespaces with Nokogiri::Builder
# Dealing with namespaces in Nokogiri.
#
# First thing you must do is abandon what you're used to with Builder,
# namespaces aren't just attributes on an element, they uniquely identify
# what sort of element you are building and, as such, you are better off
# specifying them manually.
#
# The key here is accessing the Nokogiri::XML::Element being built with
# b.parent, then you can set the namespace (distinguished by an element
# with a prefix such as "soap12:Envelope") or add a default namespace