Skip to content

Instantly share code, notes, and snippets.

View vandro's full-sized avatar

Vandro Neves dos Santos vandro

View GitHub Profile
@vandro
vandro / postgres-cheatsheet.md
Created January 13, 2020 15:43 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
apt-get update
apt-get install oracle-java7-installer
exit
@vandro
vandro / jsKeyCode.txt
Created March 15, 2018 15:48 — forked from lbj96347/jsKeyCode.txt
javascript Key Code
keycode 8 = BackSpace BackSpace
keycode 9 = Tab Tab
keycode 12 = Clear
keycode 13 = Enter
keycode 16 = Shift_L
keycode 17 = Control_L
keycode 18 = Alt_L
keycode 19 = Pause
keycode 20 = Caps_Lock
keycode 27 = Escape Escape
@vandro
vandro / install_pdo_sqlsrv.sh
Created February 8, 2018 15:29 — forked from joecampo/install_pdo_sqlsrv.sh
Install Official MSSQL driver for Unbuntu 14.04 - pdo_sqlsrv
#!/bin/bash
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo -i export CPPFLAGS="-DSIZEOF_LONG_INT=8"
sudo apt-get -y install gcc-5 g++-5
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 60 --slave /usr/bin/g++ g++ /usr/bin/g++-5
cd ~
echo "Configuring the unixODBC 2.3.1 Driver Manager"
@vandro
vandro / disable_tracker.sh
Created August 16, 2017 14:56 — forked from DanyHenriquez/disable_tracker.sh
Disable tracker Ubuntu 16.04
echo -e "\nHidden=true\n"|sudo tee --append /etc/xdg/autostart/tracker-extract.desktop
echo -e "\nHidden=true\n"|sudo tee --append /etc/xdg/autostart/tracker-miner-apps.desktop
echo -e "\nHidden=true\n"|sudo tee --append /etc/xdg/autostart/tracker-miner-fs.desktop
echo -e "\nHidden=true\n"|sudo tee --append /etc/xdg/autostart/tracker-miner-user-guides.desktop
echo -e "\nHidden=true\n"|sudo tee --append /etc/xdg/autostart/tracker-store.desktop
gsettings set org.freedesktop.Tracker.Miner.Files crawling-interval -2
gsettings set org.freedesktop.Tracker.Miner.Files enable-monitors false
tracker reset --hard
@vandro
vandro / chtml-ajaxsubmitbutton.md
Last active August 5, 2017 20:52 — forked from umidjons/chtml-ajaxsubmitbutton.md
Yii: Using `CHtml::ajaxSubmitButton` in active forms

Using CHtml::ajaxSubmitButton in active forms

<div class="form-group">
	<div class="col-sm-12 text-right">
		<?=
		CHtml::ajaxSubmitButton( Yii::t( 'zr', 'Add' ), [ 'createProperty' ],
			[
				'type'     => 'POST',
				'dataType' => 'json',
@vandro
vandro / number-format.md
Created August 5, 2017 20:50 — forked from umidjons/number-format.md
Yii: Using Number formatter in Yii

Using Number formatter in Yii

<?php
Yii::app()->numberFormatter->formatCurrency(1234.5678, 'USD'); // 1 234,57 $
Yii::app()->numberFormatter->formatCurrency(1234.5678, 'EUR'); // 1 234,57 €
Yii::app()->numberFormatter->formatCurrency(1234.5678, 'RUB'); // 1 234,57 руб.

It is easy do this with wrapper function:

@vandro
vandro / many-serverfileinput-widgets.md
Created August 5, 2017 20:49 — forked from umidjons/many-serverfileinput-widgets.md
Yii: Using more than one ServerFileInput widgets on a page

Using more than one ServerFileInput widgets on a page

I need ServerFileInput widget without model and attribute, just to select file on a server or to upload file to the server, then select it. In advance I don't know how much inputs such widgets will be on a page. Therefore, I add temporary field to the model to use with this widget, then plan to clone it with jQuery.

<?php
class MyModel extends CActiveRecord
{
	public $my_attachment; // used only to generate elFinder.ServerFileInput widget
	// ...
@vandro
vandro / multilang-app-name.md
Created August 5, 2017 20:48 — forked from umidjons/multilang-app-name.md
Yii: Multilingual/Translatable Application name

Multilingual application name

We can't directly translate application name in config files as following:

<?php
return [
	'basePath'       => dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '..',
	'name'           => Yii::t('domain', 'My Application'), // this doesn't work!!!
	// ...
@vandro
vandro / prettify-json-in-php.md
Created August 5, 2017 20:38 — forked from umidjons/prettify-json-in-php.md
Prettify JSON data in PHP

Prettify JSON in PHP

My JSON data looks like as this:

{"attributes":{"id":"146","thumbnail":"\/uploads\/files\/Oreilly.Learning.JavaScript.Design.Patterns.May.20121398922870.1667.thumb.jpg","title":"\u0422\u0435\u0441\u0442 \u04b3\u0443\u0436\u0436\u0430\u0442 5","slug":"test-huzhzhat-5","created_at":"2014-04-30 15:54:24","edited_at":{"expression":"NOW()","params":[]},"author_id":"1","source_title":"","source_url":"","status":"0","allow_comments":"0","category_id":"2","language":"4","trans_ru":"0","trans_uz_latn":"0","trans_uz":"146","trans_en":"0","content_file":"\/uploads\/files\/Oreilly.Learning.JavaScript.Design.Patterns.May.20121398922870.1667.pdf"}}

Here is how I prettify my JSON data: