Skip to content

Instantly share code, notes, and snippets.

View mahadazad's full-sized avatar

Muhammad Mahad Azad mahadazad

View GitHub Profile
@mahadazad
mahadazad / squareup.sh
Created September 18, 2018 18:00 — forked from akagr/squareup.sh
Squares up rectangular images by filling empty space with blur of same image
convert $1 -resize 826x826^ -gravity center -crop 826x826+0+0 +repage -blur 0x8 temp.jpg
convert temp.jpg $1 -resize 826x -gravity center -composite -matte "./output/$1-out.jpg"
@mahadazad
mahadazad / remove_script_tags.php
Created January 11, 2017 08:13 — forked from wkjagt/remove_script_tags.php
Remove script tags from html
<?php
function removeDomNodes($html, $xpathString)
{
$dom = new DOMDocument;
$dom->loadHtml($html);
$xpath = new DOMXPath($dom);
while ($node = $xpath->query($xpathString)->item(0)) {
$node->parentNode->removeChild($node);
}
@mahadazad
mahadazad / gist:8440e3ea4a0e2c3084e3394db8b32f43
Created December 29, 2016 04:19
Elastic Search - Search With Hyphens
PUT /store
{
"settings": {
"analysis": {
"analyzer": {
"whitespaced": {
"type": "custom",
"char_filter": ["html_strip"],
"tokenizer": "whitespace",
"filter": ["lowercase"]
@mahadazad
mahadazad / movie-titles.rb
Created December 29, 2016 03:52 — forked from karmi/movie-titles.rb
Multiple analyzers and query fields in Elasticsearch for auto-completion
require 'tire'
# Tire.configure { logger STDERR, level: 'debug' }
Tire.index('movie-titles') do
delete
create \
settings: {
index: {
analysis: {
@mahadazad
mahadazad / install-gm-w-librvg.sh
Created July 25, 2016 15:45 — forked from whyvez/install-gm-w-librvg.sh
Installs ImageMagick --with-librsvg on Amazon Linux
export PKG_CONFIG_PATH=/usr/lib64/pkgconfig:/usr/lib/pkgconfig
export PATH=/usr/bin:$PATH
export LDFLAGS=-L/usr/lib64:/usr/lib
export LD_LIBRARY_PATH=/usr/lib64:/usr/lib
export CPPFLAGS=-I/usr/include
sudo yum-config-manager --enable epel
#sudo yum update -y
sudo yum install -y gcc gcc-c++ glib2-devel.x86_64 libxml2-devel.x86_64 libpng-devel.x86_64 \
libjpeg-turbo-devel.x86_64 gobject-introspection.x86_64 gobject-introspection-devel.x86_64
@mahadazad
mahadazad / flatten.js
Created May 24, 2016 07:41
Flatten array
const flatten = e => {
return e.reduce((i, e) => i.concat(Array.isArray(e) ? flatten(e) : e), []);
}
Dockerfile
docker build -t vendor/image-name .
# use -it for interacitve mode defining an entry point eg bash
docker run -it vendor/image-name bash
docker run -d -p host-port:container-port vendor/image-name
boot2docker ip
@mahadazad
mahadazad / multer-to-s3.js
Created September 27, 2015 19:51 — forked from adon-at-work/multer-to-s3.js
Sample File Upload From Multer to S3
var AWS = require('aws-sdk'),
fs = require('fs');
// http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html#Credentials_from_Disk
AWS.config.loadFromPath('./aws-config.json');
// assume you already have the S3 Bucket created, and it is called ierg4210-shopxx-photos
var photoBucket = new AWS.S3({params: {Bucket: 'ierg4210-shopxx-photos'}});
function uploadToS3(file, destFileName, callback) {
@mahadazad
mahadazad / 1-proposal.md
Last active September 15, 2015 11:32 — forked from JedWatson/1-proposal.md
Proposal: adding reverse-relationship population to Mongoose (as implemented in KeystoneJS)

I've developed a useful feature in KeystoneJS that lets you populate a relationship from either side, while only storing the data on one side, and am looking for feedback on whether it is something that could / should be brought back into mongoose itself. (It might be possible to add as a separate package but I suspect there'd be too much rewriting of mongoose internals for that to be a good idea).

I've added this as an issue in mongoose for consideration: #1888 but am leaving this gist in place because the examples are easier to read.

I've used Posts and Categories as a basic, contrived example to demonstrate what I'm talking about here; in reality you'd rarely load all the posts for a category but there are other real world cases where it's less unreasonable you'd want to do this, and Posts + Categories is an easy way to demo it.

The problem

The built-in population feature is really useful; not just for

@mahadazad
mahadazad / app.js
Last active August 29, 2015 14:26 — forked from jmdobry/app.js
js-data + js-data-firebase + js-data-localstorage
var fb = new DSFirebaseAdapter({
basePath: 'https://my-app.firebase.io'
});
var ls = new DSLocalStorageAdapter();
var store = new JSData.DS({
// After creating an item, sync it to localStorage
afterCreate: function (resource, data) {
return ls.create(resource, data);