Skip to content

Instantly share code, notes, and snippets.

Avatar

Rohit Bhute rvbhute

View GitHub Profile
@rvbhute
rvbhute / mail vs Mail
Created Mar 10, 2015
Two ways to send emails from Laravel app
View mail vs Mail
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!');
});
View apache_cors_example
# 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
View ractive.js
// 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 / psmem.sh
Created Mar 22, 2013
Useful snippet to calculate total memory used by a process
View psmem.sh
#!/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 Apr 4, 2013
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.
View create-cbz.sh
#!/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 Apr 10, 2013
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
View create-cbz.desktop
[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
View gist:6315810
<?php
$sendToQueue = function($num) {
$parameters = []; // parameters including $num
Rabbit::enqueue('comms', 'sms', $parameters, 'topic');
};
array_walk($numbers, $sendToQueue($num));
@rvbhute
rvbhute / gist:2dac82a5a5d40ebc9c2b
Last active Jan 8, 2016
apt errors on deb.nodesource.com
View gist:2dac82a5a5d40ebc9c2b
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 Jan 8, 2016
output of curl command for all 3 ISP
View gist:3937ff7c414f774b85cf
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 Nov 23, 2017 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet
View postgres-cheatsheet.md

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)