Skip to content

Instantly share code, notes, and snippets.

View jonalvarezz's full-sized avatar
🦑

Jonathan Alvarez jonalvarezz

🦑
View GitHub Profile
@jonalvarezz
jonalvarezz / Nginxg frontend proxy for Ghost
Created January 27, 2014 05:40
Nginx as frontend proxy for Ghost
server {
server_name www.sitedomain.com;
rewrite ^ http://sitedomain.com$request_uri? permanent;
}
server {
listen 0.0.0.0:80;
server_name sitedomain.com;
access_log /var/log/nginx/sitedomain.log;
@jonalvarezz
jonalvarezz / MySQLDump Backup-Restore
Created March 10, 2014 23:47
Snippet for quickly MySQLDump Backup/Restore databases
# Backup
mysqldump -u user -p'user-password' database_name > dumpfilename.sql
# Restore
mysqldump -u user -p'user-password' database_name < dumpfilename.sql
@jonalvarezz
jonalvarezz / Tar with compression
Created March 10, 2014 23:53
How to Tar&Untar compression files
## See http://www.linfo.org/tar.html
# Tar & Compress: -j (for bzip2), -z (for gzip) and -Z (for compress)
tar -cvjf files.tar.bz2 file4 file5 file6
# Decompress: -x
tar -xjvf files.tar.bz2
@jonalvarezz
jonalvarezz / Sticky navigation
Created August 22, 2014 19:49
jQuery snippet to enable/disable a sticky nav based on his distance from window top
var _window = $(window),
nav = $('#navigation');
_window.ready(function(){
var navOffset = nav.offset().top;
_window.scroll(function(){
var scrollPos = _window.scrollTop();
if( scrollPos > navOffset ) {
nav.addClass('fix');
@jonalvarezz
jonalvarezz / Prime number
Created October 7, 2014 05:49
Prime numbers algorithm in Javascript
function isPrime(number) {
// If your browser doesn't support the method Number.isInteger of ECMAScript 6,
// you can implement your own pretty easily
if (typeof number !== 'number' || !Number.isInteger(number)) {
// Alternatively you can throw an error.
return false;
}
if (number < 2) {
return false;
@jonalvarezz
jonalvarezz / gist:5ad9c3ffadb195e6bbb3
Last active August 29, 2015 14:09
Create new DB and DB User in MySQL
# DB
CREATE DATABASE wordpress;
# User
CREATE USER wordpressuser@localhost;
# User -> DB
SET PASSWORD FOR wordpressuser@localhost= PASSWORD("password");
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'password';
@jonalvarezz
jonalvarezz / top 5 directories space used
Last active August 29, 2015 14:11
Get top 5 directories in terms of space used
# From: http://stackoverflow.com/questions/23393284/how-to-check-which-directory-is-occupying-more-space-on-a-unix-machine
du -k -d1 /path/to/directory | sort -rn | head -5
@jonalvarezz
jonalvarezz / wp default post featured image
Last active August 29, 2015 14:13
Automatically Set Featured Image On A Post
<?php
function autoset_featured() {
global $post;
$already_has_thumb = has_post_thumbnail($post->ID);
if (!$already_has_thumb) {
$attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
set_post_thumbnail($post->ID, $attachment_id);
}
@jonalvarezz
jonalvarezz / NodeList to Array
Created February 11, 2015 20:42
Convert a NodeList to Array
// Convert a NodeList to Array
// http://davidwalsh.name/nodelist-array
var nodesArray = [].slice.call(document.querySelectorAll("div"));
@jonalvarezz
jonalvarezz / xattr-remove
Created April 22, 2015 16:29
Remove all extended attributes (xattr) in a directory
# Remove all extended attributes (xattr) in a directory
# i.e: drwxr-xr-x@ directory/file -> drwxr-xr-x directory/file
xattr -c -r directory/