Skip to content

Instantly share code, notes, and snippets.

@ijmorgado
ijmorgado / instructions.md
Created October 9, 2018 18:38 — forked from zentralwerkstatt/instructions.md
Unix cheat sheet

Commands

  • nmcli: Control network manager from command line (see man nmcli)
  • df -h: Show disk space for humans
  • scp file user@server:path/file: Transfer file over SSH
  • whereis command: Path to command
  • ssh user@server: Start SSH sessiom (exit with exit)
  • ls -lah dir: Show content of directory for humans, including hidden files
  • cd dir: Change directory
  • mkdir: Create directory
@ijmorgado
ijmorgado / remove_from_datatable.js
Created June 16, 2013 04:11
This is just one way to remove a row from a table wrapped with dataTable jquery plugin, wich is a litle bit rare because to do that we can't just remove the element from the Dom...we have also to remove it from the dataTable plugin to refresh the counters and the text around the table :)
var oTable = $("#whatever").dataTable({
// ....options here
});
// then we can do...
$(this).parents("TR").fadeOut("slow", function () {
var pos = oTable.fnGetPosition(this);
oTable.fnDeleteRow(pos);
});
## The Problem
Standard practices say no non-root process gets to talk to the Internet on a port less than 1024. How, then, could I get Node talking on port 80 on EC2? (I wanted it to go as fast as possible and use the smallest possible share of my teeny tiny little micro-instance's resources, so proxying through nginx or Apache seemed suboptimal.)
## The temptingly easy but ultimately wrong solution:
Alter the port the script talks to from 8000 to 80:
}).listen(80);
@ijmorgado
ijmorgado / urls.py
Created April 6, 2013 05:56
This is a small definition of custom error 404 page (Not found) on a Django view... With this kind of definition we're using a http class to generate a response by passing a RequestContext...I know...it can be done with just 1 line in the body on the function but this is another way...and could be useful for someone :=)
# ...imports and other stuff....
# This is really important when we set DEBUG = False on settings.py to define custom error pages....
handler404 = 'my_app_name.views.not_found_404'
handler500 = 'my_app_name.views.internal_error_500'
# ...urlpatterns and another stuff....
@ijmorgado
ijmorgado / whathappenedwithcomputer
Created March 27, 2013 06:40
This is just a beautiful publication made by Jean-Baptiste Queru on his g+ account...I just want to have it safe to read whenever i want.... https://plus.google.com/112218872649456413744/posts/dfydM2Cnepe
You just went to the Google home page.
Simple, isn't it?
What just actually happened?
Well, when you know a bit of about how browsers work, it's not quite that simple. You've just put into play HTTP, HTML, CSS, ECMAscript, and more. Those are actually such incredibly complex technologies that they'll make any engineer dizzy if they think about them too much, and such that no single company can deal with that entire complexity.
Let's simplify.
@ijmorgado
ijmorgado / git_commands
Last active December 15, 2015 09:49
A small list of most common git commands I use (Is really important keep it saved, because sometimes it save us time of search on official documentations and forums.... :))
----- git rm -r --cached <folder_name>
It discard of git index but not from local working copy...useful when by accident we pushed something to remote repository and then we have to remove it from that repo.
----- git remote set-url <remote_name> <new_url_here>
It can set a new url for the current repository, useful when we change the name of the repository on Github for example, as Github also change the url for this.
@ijmorgado
ijmorgado / imagecreatefrombmp.php
Created March 2, 2013 22:38
Currently php doesn't have support to create images from bmp sources, this is a small function that solves that problem...extracted from php docs forums (http://www.php.net/manual/en/function.imagecreate.php#53879)
public function ImageCreateFromBMP($p_sFile)
{ $file = fopen($p_sFile,"rb");
$read = fread($file,10);
while(!feof($file)&&($read<>""))
$read .= fread($file,1024);
$temp = unpack("H*",$read);
$hex = $temp[1];
$header = substr($hex,0,108);
if (substr($header,0,4)=="424d")
{
@ijmorgado
ijmorgado / or_predicate_with_like.php
Created February 26, 2013 23:18
This is a small piece of code to create a select statement with 2 like clauses connected by "OR". It was made in ZF2. :)
$adapter = $this->tableGateway->getAdapter();
$select = new Select();
$select->from('alb_imagen')
->columns(array('itemId' => 'id_imagen',
'value' => 'titulo'))
->limit(12)
->join(array('t' => 'alb_thumbnail'),'t.id_imagen = alb_imagen.id_imagen',array('imagen' => 'nombre'))
->where('t.tipo = \'MINI_ICON50X50\' and alb_imagen.activo =1')
->where(array(new PredicateSet(array(new Like('titulo', "%".$query."%"),
new Like('descripcion', "%$query%")
@ijmorgado
ijmorgado / sql_like.php
Created February 25, 2013 05:15
This is another really good way to make a custom sql query in ZF2 with table gateway in the model...in this case a LIKE statement... :)
$adapter = $this->tableGateway->getAdapter();
$select = new Select();
$select->from('tax_tags')
->limit(5)
->where->like('tag', "%".$query."%");
$statement = $adapter->createStatement();
$select->prepareStatement($adapter, $statement);
$result = $statement->execute();
@ijmorgado
ijmorgado / date_validator.php
Created February 9, 2013 20:21
This is a small snippet to check if a string is a correct date.
$compare = "31-10-1991";
// first validate the format...it could be: 24-05-2013,24/05/2013,24.05.2013,24-5-2013,24.5.2013,24/5/2013...or something like that(at this point we've just validated the format...not the date)
if(preg_match('/^(3[0-1]|[0-2]?[0-9])[\/.-](1[0-2]|0?[0-9])[\/.-][0-9]{4}$/',$compare)){
$date_parsed = preg_split('/[\/.-]/', $compare);
//if the format is correct we're going to see if the date is valid....for example: 31-02-2013 should be invalid....
if(!checkdate($date_parsed[1],$date_parsed[0],$date_parsed[2])){