Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Adriano Rosa adrianorsouza

🏠
Working from home
Block or report user

Report or block adrianorsouza

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@adrianorsouza
adrianorsouza / connect.js
Created Jul 23, 2019 — forked from gaearon/connect.js
connect.js explained
View connect.js
// connect() is a function that injects Redux-related props into your component.
// You can inject data and callbacks that change that data by dispatching actions.
function connect(mapStateToProps, mapDispatchToProps) {
// It lets us inject component as the last step so people can use it as a decorator.
// Generally you don't need to worry about it.
return function (WrappedComponent) {
// It returns a component
return class extends React.Component {
render() {
return (
@adrianorsouza
adrianorsouza / nginx.conf
Created Aug 2, 2018 — forked from micho/nginx.conf
nginx config for http/https proxy to localhost:3000
View nginx.conf
First, install nginx for mac with "brew install nginx".
Then follow homebrew's instructions to know where the config file is.
1. To use https you will need a self-signed certificate: https://devcenter.heroku.com/articles/ssl-certificate-self
2. Copy it somewhere (use full path in the example below for server.* files)
3. sudo nginx -s reload
4. Access https://localhost/
Edit /usr/local/etc/nginx/nginx.conf:
@adrianorsouza
adrianorsouza / generate-icns.sh
Created Mar 4, 2017
Generate icns from iconset
View generate-icns.sh
mkdir icon.iconset
sips -z 16 16 icon1024.png --out icon.iconset/icon_16x16.png
sips -z 32 32 icon1024.png --out icon.iconset/icon_16x16@2x.png
sips -z 32 32 icon1024.png --out icon.iconset/icon_32x32.png
sips -z 64 64 icon1024.png --out icon.iconset/icon_32x32@2x.png
sips -z 128 128 icon1024.png --out icon.iconset/icon_128x128.png
sips -z 256 256 icon1024.png --out icon.iconset/icon_128x128@2x.png
sips -z 256 256 icon1024.png --out icon.iconset/icon_256x256.png
sips -z 512 512 icon1024.png --out icon.iconset/icon_256x256@2x.png
sips -z 512 512 icon1024.png --out icon.iconset/icon_512x512.png
@adrianorsouza
adrianorsouza / issue-csr.md
Created Feb 26, 2017
Generate new CSR (Certificate Signed Request) to get a new certificate issued from a CA.
View issue-csr.md

Issue CSR

$ openssl req -new -newkey rsa:2048 -nodes -keyout twixar.key -out twixar.csr

CHECK CERTIFICATE COMMAND

$ openssl x509 -noout -modulus -in domain.crt | openssl md5
$ openssl rsa -noout -modulus -in domain.key | openssl md5
$ openssl req -noout -modulus -in domain.csr | openssl md5
@adrianorsouza
adrianorsouza / createUUID.js
Last active May 6, 2019
Javascript to generate UUID
View createUUID.js
function createUUID() {
// http://www.ietf.org/rfc/rfc4122.txt
var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
s[8] = s[13] = s[18] = s[23] = "-";
@adrianorsouza
adrianorsouza / NGINX-CORS+CSP.conf
Last active Aug 24, 2016
Nginx CORS and CSP configuration for wildcard origin domains
View NGINX-CORS+CSP.conf
server {
...
add_header Content-Security-Policy "default-src 'none'";
add_header X-Content-Security-Policy "default-src 'none'";
add_header X-WebKit-CSP "default-src 'none'";
add_header "Access-Control-Allow-Headers" "X-Requested-With";
if ( $http_origin ~* (https?://(.+\.)?(domain1|domain2|domain3)\.(?:me|co|com)$) ) {
View bootstrapSwitch.js
.directive('bootstrapSwitch', [
function() {
return {
restrict: 'A',
require: '?ngModel',
link: function(scope, element, attrs, ngModel) {
element.bootstrapSwitch();
element.on('switchChange.bootstrapSwitch', function(event, state) {
if (ngModel) {
@adrianorsouza
adrianorsouza / js-random-string.js
Created May 11, 2015
Create random string with Javascript
View js-random-string.js
Math.floor(Math.random()*0xFFFFFFFFFFFFFFFF).toString(36);
@adrianorsouza
adrianorsouza / renames.sh
Created May 5, 2015
Rename list of files within a given directory
View renames.sh
#!/bin/bash
# @autor: Adriano Rosa <http://adrianorosa.com>
# @file: renames.sh
# @description: basic file renamer
# @usage: ./renames.sh path/ .html .php
criteria=$1
re_match=$2
replace=$3
if [[ $criteria && $re_match && $replace ]]; then
@adrianorsouza
adrianorsouza / jQuery.scrollToElement.js
Last active Aug 29, 2015
jQuery scrollTo element effect
View jQuery.scrollToElement.js
$("body,html").animate({
scrollTop : (
$('div.element:last').offset().top // get the offset of the last element to scrollTo
- $('header.navbar').outerHeight() // get the difference whether there is fixed header element
+ $('div.element:last').outerHeight() // get the element itself height to make scroolTo be exact under the fixed header
)
},1500);
You can’t perform that action at this time.