Skip to content

Instantly share code, notes, and snippets.

View cmlenz's full-sized avatar

Christopher Lenz cmlenz

View GitHub Profile
@cmlenz
cmlenz / babel.config.js
Created April 2, 2022 15:57
Add babel-plugin-transform-import-meta plugin in test environment only
const test = process.env.NODE_ENV === 'test';
module.exports = {
plugins: [
...(test ? ['babel-plugin-transform-import-meta'] : [])
]
};
@cmlenz
cmlenz / keybase.md
Created June 3, 2015 06:56
Keybase proof

Keybase proof

I hereby claim:

  • I am cmlenz on github.
  • I am cmlenz (https://keybase.io/cmlenz) on keybase.
  • I have a public key whose fingerprint is 2ACF 2E80 0650 50DF F199 C923 02F1 A7CD 4CD9 4BEF

To claim this, I am signing this object:

@cmlenz
cmlenz / gist:8ef4ebdab696fc24335e
Created May 5, 2014 12:25
Using the data detector API for email validation. Still probably uses regular expression under the covers (NSDataDetector is a NSRegularExpression subclass), but at least uses a system method instead of a hand-coded regex pattern.
- (BOOL)isValidEmailAddress:(NSString *)text
{
NSError *error = NULL;
NSRange textRange = {0, [text length]};
NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:&error];
if (!detector) {
NSLog(@"Could not instantiate link detector for email validation: %@", error);
return NO;
}
@cmlenz
cmlenz / indexeddb.spec.js
Last active August 29, 2015 13:58
Some simple first async tests for the AngularJS IndexedDB wrapper I'm hacking on. Using Karma, Mocha and Chai.Somewhat painful but it it seems to be working rather well.
describe('IndexedDB', function() {
var provider;
beforeEach(function(done) {
module('cmlenz.indexedDB', function(indexedDBProvider) {
provider = indexedDBProvider;
provider.connect("angular-indexeddb-tests", 1, function(evt, db) {
db.createObjectStore('test', {keyPath: 'key'});
});
});
@cmlenz
cmlenz / async_mocha.spec.js
Created April 4, 2014 14:31
Can’t get even the simplest AngularJS async test to work with Karma, tried both Jasmine 2.0 and Mocha. It works when I remove the ngMock module() invocation.
angular.module('myModule', []);
describe('Async', function() {
beforeEach(function(done) {
console.log("beforeEach", done);
module('myModule', function() { // <- hangs here
console.log("got module");
setTimeout(function() {
done();
@cmlenz
cmlenz / updatestrings.py
Created May 29, 2013 21:03
Update the strings files for an Interface Builder file such as a XIB or a storyboard that uses base localization (a feature added in iOS 6 and OS X 10.8).
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
This script can update the localizable strings files for an Interface Builder
file such as a XIB or a storyboard that uses base localization (a feature added
in iOS 6 and OS X 10.8).
You invoke it by passing the path to the IB file, which should sit in a
Base.lproj directory:
@cmlenz
cmlenz / gist:1992369
Created March 7, 2012 10:13 — forked from thomasbilk/database_size.sql
Database Sizes
-- PostgreSql
SELECT
pg_database.datname AS "Database Name",
pg_database_size(pg_database.datname) / 1024.0 / 1024.0 AS "Database Size (MB)"
FROM pg_database;
-- MySql
SELECT
table_schema "Database Name",
sum( data_length + index_length ) / 1024 / 1024 "Database Size (MB)"
var http = require("http"),
sys = require("sys");
var server = http.createServer(function(request, response) {
response.sendHeader(200, {"Content-Length": "42"});
response.finish();
sys.puts("Server finished response");
}).listen(8000);
var client = http.createClient(8000, "localhost");