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" ;};'
// 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');
# 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
@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!');
});