Skip to content

Instantly share code, notes, and snippets.

View gartenfeld's full-sized avatar

David Rosson gartenfeld

View GitHub Profile
db.collection.aggregate([
{ $group: {
_id: { firstField: "$firstField", secondField: "$secondField" },
uniqueIds: { $addToSet: "$_id" },
count: { $sum: 1 }
}},
{ $match: {
count: { $gt: 1 }
}},
{ $group: {
@gartenfeld
gartenfeld / citation_block_convert.py
Last active August 29, 2015 14:10
Extracting and re-formatting XML data using BeautifulSoup.
from bs4 import BeautifulSoup
import re # Regular Expressions
import collections # Data Types
import sys # File operations
import codecs # UniCode support
import os
import locale
def inspect_file(file_name):
var results = db.sanat.aggregate([
{ $group:
{
_id: {
headword : "$headword",
senses : "$senses"
},
uniqueIds: { $addToSet: "$_id" },
count: { $sum: 1 }
}
@gartenfeld
gartenfeld / available_methods.js
Created December 3, 2014 14:25
Find out what methods an object has.
var methods = [];
for (var prop in object) {
if (typeof object[prop] === "function") {
methods.push(prop);
}
}
@gartenfeld
gartenfeld / first_import.py
Created December 3, 2014 14:36
Importing data using PyMongo.
from bs4 import BeautifulSoup
import re # Regular Expressions
import collections # Data Types
import sys # File operations
import codecs # UniCode support
import os
import random
import locale
from pymongo import Connection # For DB Connection
from pymongo.errors import ConnectionFailure # For catching exeptions
@gartenfeld
gartenfeld / drop_dups.py
Created December 3, 2014 17:51
Removing duplicates using aggregation.
from bs4 import BeautifulSoup
import re # Regular Expressions
import collections # Data Types
import sys # File operations
import codecs # UniCode support
import os
from pymongo import Connection # For DB Connection
from pymongo.errors import ConnectionFailure # For catching exeptions
def drop_dups(database, collection):
@gartenfeld
gartenfeld / letters-to-100.py
Last active August 29, 2015 14:10 — forked from peterjmag/letters-to-100.py
English words with "letter score" adding up to 100, sorted by frequency.
import re # Regular Expressions
import collections # Data Types
import sys # File operations
import codecs # UniCode support
import os
import operator
import string
def load_freq(freq_f):
@gartenfeld
gartenfeld / batch_audio_convert.txt
Created December 19, 2014 12:29
Convert audio using ffmpeg.
1. Download the binary ffmpeg: http://ffmpegmac.net/
2. Extract the executable ffmpeg file.
3. Copy it to a directory that is in your executable path, e.g. /usr/bin.
sudo cp ~/Downloads/ffmpeg /usr/bin/ffmpeg
4. Make it executable:
sudo chmod +x /usr/bin/ffmpeg
Now, in the folder with the AIFF files, run this:
for f in *.aiff; do ffmpeg -i "$f" "${f%.aiff}.ogg" -aq:a 2; done
@gartenfeld
gartenfeld / keypress.js
Last active August 29, 2015 14:11
Keypress for international keyboards.
$('body').keypress(
function (e) {
console.log(
String.fromCharCode( e.which )
);
}
);
@gartenfeld
gartenfeld / set_env.sh
Created December 22, 2014 05:13
Setting OpenShift ENV variables.
rhc set-env VARIABLE1=VALUE1 VARIABLE2=VALUE2 -a app_name