Skip to content

Instantly share code, notes, and snippets.

@sepehr
sepehr / get_daterange_timestamps.php
Created August 27, 2013 09:16
PHP: Get corresponding timestamp boundaries of a daterange
<?php
/**
* Generates timestamp bounderies for the passed date range name.
*
* @param string $range Date range name.
*
* @return array
*/
function get_daterange_timestamps($range)
@sepehr
sepehr / fix_string_mongodates.js
Last active December 30, 2015 06:18
MongoDB: Fix string-typed MongoDate fields
db.jobseekers
// Find all documents with a string-typed date field
.find({date: {$type: 2}})
// Convert each date field to a ISODate based on its "created_on" raw timestamp
.forEach(function(doc) {
// The JSON <date> representation that Mongo expects is a 64-bit signed
// integer representing milliseconds since the epoch.
// We need to multiply the unixtime seconds value by 1000.
//
@sepehr
sepehr / osx_unlock.sh
Last active January 1, 2016 20:49
OSX: Recursively unlock files
find ~/Dev/www -flags +uchg -print0 | xargs -0 chflags nouchg
@sepehr
sepehr / find_n_chmod.sh
Last active January 1, 2016 21:39
Shell: Chmod recursively by type
find . -type f -print0 | xargs -0 chmod 0644
find . -type d -print0 | xargs -0 chmod 0755
@sepehr
sepehr / crlf2lf.sh
Last active January 2, 2016 14:19
Shell: Convert CRLF to LF
tr -d '\r' < /path/to/crappy/windows-eol.csv > /path/to/shiny/unix-eol.csv
@sepehr
sepehr / shell_history_mail.sh
Last active January 19, 2016 03:15
Shell: History via mail
#!/bin/bash
tail -n 100 ~/.bash_history | mail -v -s "Shell history log of '$HOSTNAME'" lajevardi+logs@gmail.com
@sepehr
sepehr / gitignore2svnignore.sh
Created June 24, 2014 08:30 — forked from iegik/gitignore2svnignore.sh
Shell: Convert .svnignore to .gitignore & viceversa
#!/bin/bash
cat .gitignore | sed 's/^/\.\//g;s/\(.*\)\/\([0-9a-zA-Z\*\?\.]*\)$/svn propedit svn:ignore "\2" \1 /mg' | bash
@sepehr
sepehr / dos2unix.sh
Last active November 10, 2015 22:51
Shell: Recursively convert line endings to LF
find . -type f ! -regex ".*\/\.svn\/.*" -exec dos2unix {} \;
@sepehr
sepehr / cron_times.sh
Last active November 10, 2015 22:50
Shell: /etc/cron.daily tasks run time
# When does cron.daily, cron.hourly, etc. run on a system?
grep run-parts /etc/crontab
@sepehr
sepehr / find_n_exec.sh
Last active November 10, 2015 22:49
Shell: Recursively delete particular files/dirs
find . -type f -name "__MACOSX" -exec rm -rf {} \;