Skip to content

Instantly share code, notes, and snippets.

@simonewebdesign
simonewebdesign / ajax-spec.js
Created February 24, 2015 09:50
Chai expectations and Sinon.js (test spies) example checking if an object contains a certain key/value pair
it('will POST data in JSON format', () => {
let promise = ajax('POST', '/somewhere', {foo: "bar"})
.then((result) => {
expect(result).to.equal('OK');
});
expect(requests[0].requestBody).to.equal(JSON.stringify({foo: "bar"}));
requests[0].requestHeaders.should.have.property("Content-Type").with.length("application/json;charset=utf-8".length);
assert.propertyVal(requests[0].requestHeaders, "Content-Type", "application/json;charset=utf-8");
expect(requests[0].requestHeaders).to.have.property("Content-Type", "application/json;charset=utf-8");
requests[0].respond(200, {}, 'OK');
@simonewebdesign
simonewebdesign / mmv.sh
Last active August 30, 2018 03:44
mmv: move/copy/append/link multiple files by wildcard patterns
# Create multiple folders
$ mkdir -p source/tags/modules/{dob,grid,radio,set,telephone,text}
# Move multiple files by wildcard pattern
$ mmv "source/tags/modules/*.txt" "source/tags/modules/#1/#1.txt"
# Create multiple files by wildcard pattern (e.g. same name as their folder)
$ cd source/tags/modules
# then...
@simonewebdesign
simonewebdesign / js_libs.md
Created December 16, 2014 16:19
JavaScript libraries
@simonewebdesign
simonewebdesign / postgres.sh
Last active May 7, 2021 18:05
Postgres Cheatsheet for Linux and macOS: Login on psql and create a new user role. Also dump and restore.
# Install postgres first (e.g. OS X):
brew install postgres
# After installation... if user not created:
# This is a wrapper around CREATE ROLE, you might not have it.
# BTW, a role is the same as a user.
# A role is an entity that can own database objects and have database privileges;
# a role can be considered a "user", a "group", or both depending on how it is used.
createuser --superuser postgres # -s works as well
@simonewebdesign
simonewebdesign / replace.sql
Last active August 29, 2015 14:07
PostgreSQL regexp_replace example
CREATE OR REPLACE FUNCTION isFoo(text) RETURNS BOOLEAN AS '
SELECT $1 ~* ''insert_regex_here'' AS RESULT
' LANGUAGE SQL;
UPDATE blocks
SET content=(SELECT regexp_replace(content, 'insert_regex_here', 'insert_replace_text_here'));
;--WHERE isFoo(content);
SELECT *
FROM blocks
//
// ViewController.m
// Animation
//
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *image;
@property (strong, nonatomic) IBOutlet UILabel *label;
@simonewebdesign
simonewebdesign / .htaccess
Created May 5, 2014 21:31
.htaccess redirect all requests to a subfolder
# /.htaccess
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public/$1 [L]
@simonewebdesign
simonewebdesign / regex.rb
Created April 21, 2014 22:49
Sublime Text find/replace anything (code) between HTML tags
find: <pre>(((?!<\/pre>).|\n)+)<\/pre>
replace: ``` javascript\n$1\n```
@simonewebdesign
simonewebdesign / deploy.sh
Created April 19, 2014 15:08
Deploy a Jekyll site via LFTP
lftp -e 'mirror -R -e -v public; bye' -u user,pass ftp://ftp.example.com
@simonewebdesign
simonewebdesign / pre-push
Created March 12, 2014 22:08
git hook to deploy a site via FTP (ftp-push)
#!/bin/sh
echo "Running pre-push hook..."
branch=`git rev-parse --abbrev-ref HEAD`
if [ $branch == "master" ]; then
echo "Deploying to FTP..."
git ftp push
echo "done!"
fi