Skip to content

Instantly share code, notes, and snippets.

View guiliredu's full-sized avatar
🚀
Working

Guilherme Dias Redü guiliredu

🚀
Working
View GitHub Profile
/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* STYLES GO HERE */
}
/* Smartphones (landscape) ----------- */
@media only screen
Verifying that +oguilherme is my blockchain ID. https://onename.com/oguilherme
@guiliredu
guiliredu / fileapi.js
Created April 26, 2016 12:41
HTML5 File API - Get file name
document.getElementById("js-input-file").addEventListener("change", function(){
$('#js-input-fake').html(this.files[0].name);
}, false);
@guiliredu
guiliredu / js-slug.js
Last active May 6, 2016 19:22
Javascript SLUG
var toSlug = function(str) {
str = str.replace(/^\s+|\s+$/g, ''); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
var from = "ãàáäâẽèéëêìíïîõòóöôùúüûñç·/_,:;";
var to = "aaaaaeeeeeiiiiooooouuuunc------";
for (var i=0, l=from.length ; i<l ; i++) {
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
}
@guiliredu
guiliredu / js-search.js
Last active May 8, 2016 18:46
Seach an array of itens for a value and show/hide itens based on ID
$('.js-chat-search').on('keyup', function(){
var s = $(this).val();
if(s != ""){
$('.js-chat-item').hide();
for (var j = 0; j < userList.length; j++) {
if (userList[j][0].toUpperCase().match(s.toUpperCase())){
$('.js-chat-item-'+userList[j][1]).show();
}
}
}else{
@guiliredu
guiliredu / font-wesome-after-before.css
Created May 16, 2016 19:31
Use a font awesome icon as a :after or :before
element:before {
font-family: FontAwesome;
content: "\f095"; /* code of the icon */
}
@guiliredu
guiliredu / js-svg-to-png-replace.js
Created July 5, 2016 18:02
Check with modernizr if SVG support is avaiable and replace to PNG
if (!Modernizr.svg) {
$('.js-svg').each(function(){
$(this).attr('src', $(this).attr('src').replace('.svg', '.png'));
});
}
@guiliredu
guiliredu / .htaccess
Last active July 20, 2016 14:16
Configura CORS in .htaccess
<IfModule mod_rewrite.c>
Header add Access-Control-Allow-Origin: "domain.tld"
Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
Header add Access-Control-Allow-Headers: "X-Requested-With, Content-Type"
RewriteEngine on
RewriteBase /
</IfModule>
@guiliredu
guiliredu / jquery-xhr.js
Last active August 19, 2016 19:38
Example of jQuery XHR calls
// POST
$.post('/url', parameters, function(data) {
console.log(data);
});
// GET
$.get('/url', parameters, function(data) {
console.log(data);
});
// JSON
$.getJSON('/url', parameters, function(data) {
@guiliredu
guiliredu / google-maps-geocode.php
Created April 19, 2017 13:28
Google Maps Geocode query in backend with PHP
<?php
function getLatLongByAddress($address){
$prepAddr = str_replace(' ','+',$address);
$geocode = file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');
$output = json_decode($geocode);
$return['latitude'] = $output->results[0]->geometry->location->lat;
$return['longitude'] = $output->results[0]->geometry->location->lng;
return $return;