Skip to content

Instantly share code, notes, and snippets.

@sepehr
sepehr / svn_rm_deleted.sh
Last active Nov 10, 2015
SVN: Remove Deleted Files
View svn_rm_deleted.sh
svn st | grep '^!' | awk '{print $2}' | xargs svn delete --force
@sepehr
sepehr / mongodb_subdoc_query.js
Last active Nov 18, 2015
MongoDB: Remove an array from an embedded document
View mongodb_subdoc_query.js
//
// Find documents with sub-document query:
//
db.collection_name.find({
relays: {
$elemMatch: {
timestamp: {$gte: 1447628400},
status: "RELAY_STATUS_ERROR_SUBMIT",
app_id: ObjectId("537cb1b5fc20a0eb47000000")
}
@sepehr
sepehr / fix_string_mongodates.js
Last active Dec 30, 2015
MongoDB: Fix string-typed MongoDate fields
View fix_string_mongodates.js
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 Jan 1, 2016
OSX: Recursively unlock files
View osx_unlock.sh
find ~/Dev/www -flags +uchg -print0 | xargs -0 chflags nouchg
@sepehr
sepehr / find_n_chmod.sh
Last active Jan 1, 2016
Shell: Chmod recursively by type
View find_n_chmod.sh
find . -type f -print0 | xargs -0 chmod 0644
find . -type d -print0 | xargs -0 chmod 0755
@sepehr
sepehr / crlf2lf.sh
Last active Jan 2, 2016
Shell: Convert CRLF to LF
View crlf2lf.sh
tr -d '\r' < /path/to/crappy/windows-eol.csv > /path/to/shiny/unix-eol.csv
@sepehr
sepehr / shell_history_mail.sh
Last active Jan 19, 2016
Shell: History via mail
View shell_history_mail.sh
#!/bin/bash
tail -n 100 ~/.bash_history | mail -v -s "Shell history log of '$HOSTNAME'" lajevardi+logs@gmail.com
@sepehr
sepehr / Default(OSX).txt
Last active Jan 19, 2016
Sublime Settings
View Default(OSX).txt
[
{ "keys": ["ctrl+super+a"], "command": "alignment" },
{ "keys": ["ctrl+super+f"], "command": "reindent", "args": {"single_line": false}},
{ "keys": ["super+v"], "command": "paste_and_indent" },
{ "keys": ["super+shift+v"], "command": "paste" },
{ "keys": ["super+backspace"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Delete Line.sublime-macro"} },
]
@sepehr
sepehr / lcdhype-asus-g50-g70.txt
Last active Jan 19, 2016
LCDHype script for Asus G50/G70 LCDs.
View lcdhype-asus-g50-g70.txt
#Header
%KeyInit()
%Param.AvoidPluginCleanUp()
%Common.SetPriority(140)
%Graph.SetTextArea(0,0,255,31)
%Graph.Font('OCR-A',10,1)
%DefVar(xPos,Local=105)
%DefVar(yPos,Local=16)
%DefVar(an=0)
%DefVar(km,Global)
@sepehr
sepehr / tsv2csv.py
Last active Feb 4, 2016
Python: Bulk convert .tsv to .csv
View tsv2csv.py
#!/usr/bin/python
import glob
import csv
import sys
import os
# Check args
if len(sys.argv) < 2:
sys.exit('Usage: tsv2csv.py /path/to/dir')