Skip to content

Instantly share code, notes, and snippets.

@wytten
wytten / lcase.js
Created April 21, 2014 19:53
MongoDB: Convert 'database' attribute of all documents in collection to lower case
db.GroovyScriptResult.find({database: {$ne:null}}).forEach(
function (e) {
db.GroovyScriptResult.update({_id: e._id}, {$set: {database: e.database.toLowerCase() } })
}
)
@wytten
wytten / Query-template.js
Created April 21, 2014 19:35
Perl Template
printjson(db.GroovyScriptResult.findOne({name : "[%script%]", version : "[%version%]", database : "[%database%]", stackTrace:null}))
@wytten
wytten / Example.java
Last active January 11, 2019 06:29
Simple Active Directory authentication with Spring LDAP
import static org.springframework.ldap.query.LdapQueryBuilder.query;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.AuthenticationException;
public class Example {
@Autowired
LdapTemplate ldapTemplate;
public boolean authenticate(String uid, String credentials) {
import com.gmongo.GMongo
def gmongo = new GMongo('localhost:27017')
def db = gmongo.getDB('nucleus')
db.GroovyScriptResult.find([name: ~/Finance/, version: 'trunk', database: [ $ne:'opsd' ]]).each {
println it
}
@wytten
wytten / gist:9790969
Created March 26, 2014 19:12
MongoDB update all
db.scores.update({}, {$set:{score:77}}, {multi:true});
@wytten
wytten / gist:9790018
Created March 26, 2014 18:28
MongoDB dot notation
db.catalog.find({price:{$gt:10000}, "reviews.rating":{$gte:5}})
@wytten
wytten / static_server.js
Last active August 29, 2015 13:57 — forked from ryanflorence/static_server.js
Changed to serve files only out of a subdirectory named 'public_html'
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd() + "/public_html", uri);
@wytten
wytten / agent
Last active January 3, 2016 21:19 — forked from anonymous/april_temp_sensor
Updated original april_temp_sensor to remove use of deprecated methods, to remove the use of pin2 for activating the lamp, and to use CSV format for communication with xively.com. Also added agent code taken from https://xively.com/dev/tutorials/electric_imp to which I have made trivial modifications.
const FEED_ID = "YOUR_FEED_ID";
const API_KEY = "YOUR_API_KEY";
// Accept CSV from device, then format request to and accept response from xively.com
device.on("data", function(feedCSV) {
server.log(feedCSV);
local xively_url = "https://api.xively.com/v2/feeds/" + FEED_ID + ".csv";
local request = http.put(xively_url, {"X-ApiKey":API_KEY, "Content-Type":"text/csv", "User-Agent":"Xively-Imp-Lib/1.0"}, feedCSV);
local response = request.sendsync();
if(response.statuscode != 200) {
@wytten
wytten / StopCondition
Created October 28, 2013 17:19
Add a method to File class: A variation of eachLine that accepts a stopClosure
/*
* Add a method to File class: A variation of eachLine that accepts a stopClosure
*/
File.metaClass.eachLineBreak = { stopClosure, workClosure ->
for (Iterator iter = delegate.iterator(); iter.hasNext();) {
def value = iter.next()
if (stopClosure.call(value)) {
break
} else {
workClosure.call(value)
@wytten
wytten / gist:7085017
Created October 21, 2013 14:41
Oracle SQL to report on existing table indices
select
b.uniqueness, a.index_name, a.table_name, a.column_name
from
all_ind_columns a, all_indexes b
where
a.index_name=b.index_name and
a.table_name = upper('&table_name')
order by
a.table_name, a.index_name, a.column_position;