Skip to content

Instantly share code, notes, and snippets.

View giovannibenussi's full-sized avatar

Giovanni giovannibenussi

View GitHub Profile
@dmitry
dmitry / debug_webmock.rb
Created August 11, 2014 20:23
debug webmock
WebMock.after_request do |request_signature, response|
p request_signature.body
end
@ktheory
ktheory / enumerable_pluck.rb
Created February 15, 2012 22:54
An Enumerable#pluck method for ruby
module Enumerable
def pluck(key)
map {|obj| obj[key] }
end
end
@isundaylee
isundaylee / Gemfile Template
Created December 16, 2013 19:34
Ruby: Gemfile template.
# Add rubygems.org to source.
# Just a funny line.
source 'https://rubygems.org'
@sarathlal-old
sarathlal-old / DNS prefetching
Created August 25, 2016 04:56
Common Prefetch Links
<!-- Amazon S3 -->
<link rel="dns-prefetch" href="//s3.amazonaws.com">
<!-- Google CDN -->
<link rel="dns-prefetch" href="//ajax.googleapis.com">
<!-- Microsoft CDN -->
<link rel="dns-prefetch" href="//ajax.microsoft.com">
<link rel="dns-prefetch" href="//ajax.aspnetcdn.com">
@cupakromer
cupakromer / gist:3371003
Created August 16, 2012 15:23
each_with_object vs inject
my_array = %w[test one two three]
# Inject takes the value of the block and passes it along
# This often causes un-intended errors
my_array.inject({}) do |transformed, word|
puts transformed
transformed[word] = word.capitalize
end
# Output:
# {}
@jaredpalmer
jaredpalmer / EmailInput.jsx
Created November 29, 2017 18:06
Formik async email signup input
import React from 'react';
import debounce from 'utils/debounce';
class EmailInput extends React.Component {
checkEmail = value => {
// only check if the field passes Yup email validation first
if (
!this.props.form.errors[this.props.name].includes(
'invalid' /* or whatever your error message is*/
)
@lmosele
lmosele / Usage.js
Created July 8, 2019 21:07
React On Click Outside of Element Hook
// clicking outside of div will hide <p>
const Menu = props => {
const { ref, isComponentVisible } = useComponentVisible(true);
return (
<div ref={ref}>
{isComponentVisible && <p>{props.children}</p>}
</div>
);
};
@arnaldog
arnaldog / gist:f9368bcfa3a1b149db1a2b1b9dea0c44
Created September 15, 2016 14:26
Paya Generator 3000 Node JS
var express = require('express');
var app = express();
one = [ "La cueca pá los chilenos",
"Si no le gustan las cuecas",
"Hoy es 18 de Septiembre",
"Yo también voy a la ramá",
"Tu creis que no se ná",
"Yo las bailo donde sea",
"No bailo tanto pero tengo otra gracia",
@maxivak
maxivak / send_data-send_file-remote-images-download
Created January 1, 2013 23:34
Rails. Download remote image as attachment in browser
# in controller
# for local files
send_file '/path/to/file', :type => 'image/jpeg', :disposition => 'attachment'
# for remote files
require 'open-uri'
url = 'http://someserver.com/path/../filename.jpg'
data = open(url).read
send_data data, :disposition => 'attachment', :filename=>"photo.jpg"
@ysegorov
ysegorov / Jenkinsfile
Last active April 8, 2021 14:31
Jenkinsfile example
#!/usr/bin/env groovy
// https://github.com/freebsd/freebsd-ci/blob/master/scripts/build/build-test.groovy
// http://stackoverflow.com/a/40294220
// https://JENKINS_HOST/scriptApproval/ - for script approval
import java.util.Date
def isMaster = env.BRANCH_NAME == 'master'
def isDevelop = env.BRANCH_NAME == 'develop'