Skip to content

Instantly share code, notes, and snippets.

# Rename .haml files to .erb
ls *.haml | sed 's/haml//g' | xargs -i mv {}haml {}erb
@andreydjason
andreydjason / PostgresSQL
Last active August 29, 2015 14:07
Common Commands
sudo -u postgres psql
ALTER USER Postgres WITH PASSWORD 'NEW PWD';
psql -h hostname -d databasename -U username -f file.sql
$(function () {
"use strict";
// for better performance - to avoid searching in DOM
var content = $('#content');
var input = $('#input');
var status = $('#status');
// my color assigned by the server
var myColor = false;
@andreydjason
andreydjason / sublime.sh
Created May 25, 2012 17:11
Sublime Text 2 - Codes, Tips, Tricks
# Install packgage control (http://wbond.net/sublime_packages/package_control/installation) - execute in Sublime Text 2 Console:
import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print 'Please restart Sublime Text to finish installation'
# Use Regex (Regular Expressions) to find text patterns on files
# Search in Google for Regexp then use in Sublime Text - you will need to understood then to use and gain productivity, that can be helpful in many situations :)
# => Examples: https://github.com/andreydjason/SublimeText-Regexp-Utils
@andreydjason
andreydjason / apache_bench.sh
Created May 25, 2012 04:33
Web Development Benchmarking
### do a benchmark in a website with the Apache Benchmark Tool
## -n must be HIGHER than -c to have measurable results
$ ab -c10 -n100 http://google.com/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking google.com (be patient).....done
@andreydjason
andreydjason / test.rb
Created May 23, 2012 13:20
Ruby Codings :-)
#!/usr/bin/env ruby
# encoding: utf-8
# Ruby
#
# to run in a Rails environment (add the line below)
# require './config/environment'
#
# An example of how select the last item of an array that's not nil
def select_last_not_nil(options)
item = nil
@andreydjason
andreydjason / mysql.utils
Created May 21, 2012 13:17
MySQL SQL Utils
# Return the columns with status of table, including the Auto_Increment value:
=> SHOW TABLE STATUS LIKE '<table_name>'
# Return a random number:
1) => (<MinRange> + FLOOR(RAND() * (<MaxRange> - <MinRange> + 1))) as random_number
2) => FLOOR(<MinRange> + RAND() * <MaxRange>) as random_number
* Replace the values in <these_tag_type> whitin your values.
@andreydjason
andreydjason / Backup_Geral_HIVE.rb
Created May 16, 2012 16:36
Examples of using RSYNC to do Backups of local to remote, and send result by email (Ruby)
require 'date'
require 'time'
require 'net/smtp'
Dir.chdir('/home/andrey/Cronjobs/')
def verify_rsync_output(rsync_output)
if rsync_output == ''
raise RuntimeError, '* Rsync returned empty result for backup - SSH access to the server has ben set?'
end
@andreydjason
andreydjason / script.php
Created April 18, 2012 19:57
How to set variables args with command line in PHP
#!/usr/bin/php <- location of the php parser
<?php
# This script receives command line args and transforms it into an array of *params
# example from command line: ($ <- is the bash)
# $ /usr/bin/env php script.php --onevar=ThisIsMyValue --another_var=1 --some-var="some value" --integerVar=102323
# in theory, the variables accepts any kind of value, just set the value as ypu set it in PHP
error_reporting(0);
$this_script = $_SERVER["SCRIPT_NAME"];
@andreydjason
andreydjason / gist:2416031
Created April 18, 2012 19:43 — forked from philfreo/gist:2321650
mysqldump cron
#!/bin/sh
# CRON
## delete encrypted backups older than 5 days
#55 3 * * * find /path/to/backups-enc -mtime +5 -exec rm {} \;
## delete un-encrypted backups older than 1 days
#55 3 * * * find /path/to/backups -mtime +0 -exec rm {} \;
## database dump at 4am UTC = 8pm PST (9pm PDT)
#0 4 * * * /path/to/this/script