Skip to content

Instantly share code, notes, and snippets.

@rvbhute
rvbhute / psmem.sh
Created March 22, 2013 10:35
Useful snippet to calculate total memory used by a process
#!/bin/sh
# psmem.sh
# http://abdussamad.com/archives/488-Memory-usage-of-a-process-under-Linux.html
ps -C $1 -O rss | gawk '{ count ++; sum += $2 }; END {count --; print "Number of processes =",count; print "Memory usage per process =",sum/1024/count, "MB"; print "Total memory usage =", sum/1024, "MB" ;};'
@rvbhute
rvbhute / create-cbz.sh
Created April 4, 2013 07:26
Two versions for creating CBZ (Comic Book archive) files out of a directory of images. These files can be opened in comic readers. In Linux, applications like Evince also handle CBZ files with ease.
#!/bin/sh
# First version, to use only a particular file-type in a folder
for f in `ls -l | egrep '^d' | awk '{print $NF}'`
do
cd $f
zip $f.cbz *.jpg
mv $f.cbz ../$f.cbz
cd ..
@rvbhute
rvbhute / create-cbz.desktop
Created April 10, 2013 16:29
Custom KDE service menu entry to create a CBZ archive from a directory of images. Drop this file in your service menu folder - ~/.kde/share/kde4/services
[Desktop Entry]
Type=Service
ServiceTypes=KonqPopupMenu/Plugin
MimeType=inode/directory;
Actions=createCBZ
[Desktop Action createCBZ]
Name=Create CBZ
Exec=zip "%u.cbz" %u/*.*
Icon=ark
<?php
$sendToQueue = function($num) {
$parameters = []; // parameters including $num
Rabbit::enqueue('comms', 'sms', $parameters, 'topic');
};
array_walk($numbers, $sendToQueue($num));
@rvbhute
rvbhute / mail vs Mail
Created March 10, 2015 15:37
Two ways to send emails from Laravel app
mail('mail@serversforhackers.com', 'Feedback', 'This is so useful, thanks!');
Mail::send('emails.test', ['key' => 'value'], function($message)
{
$message->to('foo@example.com', 'John Smith')->subject('Welcome!');
});
# Sets CORS headers for request from example1.com and example2.com pages
# for both SSL and non-SSL
SetEnvIf Origin "^https?://[^/]*(example1|example2)\.com$" ORIGIN=$0
Header set Access-Control-Allow-Origin %{ORIGIN}e env=ORIGIN
Header set Access-Control-Allow-Credentials "true" env=ORIGIN
# Always set Vary: Origin when it's possible you may send CORS headers
Header merge Vary Origin
// my_list is an array of objects updated by ajax
var my_list = [{'id':1, 'name':'Jack'},{'id':2, 'name':'Robin'}];
// with lodash
var add_new_messages = function(data) {
var new_list = my_list;
new_list.push.apply(new_list, data);
new_list = _.uniq(new_list, 'id');
@rvbhute
rvbhute / gist:2dac82a5a5d40ebc9c2b
Last active January 8, 2016 07:21
apt errors on deb.nodesource.com
rohit@ryujin:~$ curl -v https://deb.nodesource.com
* Rebuilt URL to: https://deb.nodesource.com/
* Hostname was NOT found in DNS cache
* Trying 192.241.233.42...
* Trying 2604:a880:1:20::13b:b001...
* connect to 2604:a880:1:20::13b:b001 port 443 failed: Network is unreachable
* Failed to connect to deb.nodesource.com port 443: Network is unreachable
* Closing connection 0
curl: (7) Failed to connect to deb.nodesource.com port 443: Network is unreachable
@rvbhute
rvbhute / gist:3937ff7c414f774b85cf
Created January 8, 2016 10:49
output of curl command for all 3 ISP
rohit@ryujin:~$ curl -v https://deb.nodesource.com
* Rebuilt URL to: https://deb.nodesource.com/
* Hostname was NOT found in DNS cache
* Trying 192.241.233.42...
* Trying 2604:a880:1:20::13b:b001...
* connect to 2604:a880:1:20::13b:b001 port 443 failed: Network is unreachable
* Failed to connect to deb.nodesource.com port 443: Network is unreachable
* Closing connection 0
curl: (7) Failed to connect to deb.nodesource.com port 443: Network is unreachable
@rvbhute
rvbhute / postgres-cheatsheet.md
Created November 23, 2017 09:54 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -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)