Skip to content

Instantly share code, notes, and snippets.

View kalharbi's full-sized avatar

Khalid Alharbi kalharbi

  • Saudi Arabia
View GitHub Profile
@kalharbi
kalharbi / gist:56dd376fe49c47d9b9be
Created May 6, 2014 05:00
A custom JSON encoder that excludes null or empty pair values.
from json import JSONEncoder
class CustomJsonEncoder(JSONEncoder):
def remove_none(self, data):
if isinstance(data, dict):
return {k:self.remove_none(v) for k, v in data.items() if k and v }
elif isinstance(data, list):
return [self.remove_none(item) for item in data if item]
elif isinstance(data, set):
@kalharbi
kalharbi / gist:ac181291ccf7e601927f
Last active August 29, 2015 14:02
Retrieve zip file from MongoDB GridFS and save it in a directory
MongoClient mongoClient = new MongoClient("localhost", 27017);
DB db = mongoClient.getDB("archives");
GridFS gridGfs = new GridFS(db, "fs");
// search by metadata
BasicDBObject query = new BasicDBObject("metadata.n", "myZipFile")
.append("metadata.ver", "1.2.6");
GridFSDBFile zipFile = gridGfs.findOne(query);
File outFile = new File("/Users/Khalid/git/gists/file.zip");
outFile.createNewFile();
zipFile.writeTo(outFile);
@kalharbi
kalharbi / load_ajax.js
Created July 2, 2014 05:42
PhantomJS - Load dynamic web page content that uses AJAX
// Original code:
// https://github.com/ariya/phantomjs/blob/master/examples/waitfor.js
// https://github.com/ariya/phantomjs/blob/master/examples/rasterize.js
/**
* Wait until the test condition is true or a timeout occurs. Useful for waiting
* on a server response or for a ui change (fadeIn, etc.) to occur.
*
* @param testFx javascript condition that evaluates to a boolean,
* it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
@kalharbi
kalharbi / log.rb
Created July 11, 2014 21:30
Ruby Logging - different channels for different levels. Log errors to FILE and all levels to STDOUT.
require 'logging' # gem install logging
require 'singleton'
class Log
include Singleton
attr_accessor :log_file_name
@@file_name = nil
# set log file name
@kalharbi
kalharbi / added_perm.csv
Created October 10, 2014 17:58
Added Permissions
permission count
android.permission. 2.0
android.permission.ACCESOFS_WIFI_STATE 1.0
android.permission.ACCESS_ASSISTED_GPS 7.0
android.permission.ACCESS_BACKGROUND_SERVICE 2.0
android.permission.ACCESS_CELL_ID 2.0
android.permission.ACCESS_CHECKIN_PROPERTIES 4.0
android.permission.ACCESS_COARSE_LOCATION 1114.0
android.permission.ACCESS_COARSE_UPDATES 7.0
android.permission.ACCESS_CORSE_LOCATION 1.0
@kalharbi
kalharbi / crawler-keywords.txt
Created August 10, 2015 05:01
Keywords to feed to a mobile apps crawler
2d
3M
3d
AECOM Technology
AES
AGCO
AK Steel Holding
AM
AMR
ATT
@kalharbi
kalharbi / gulpfile.js
Created August 20, 2015 19:58
gulpfile.js with browserify, babelify, watchify, sourcemaps, gulp-connect, and node-notifier
var gulp = require("gulp");
var gutil = require("gulp-util");
var open = require("gulp-open");
var sourcemaps = require("gulp-sourcemaps");
var notifier = require("node-notifier")
var connect = require("gulp-connect");
var buffer = require("vinyl-buffer");
var source = require("vinyl-source-stream");
var chalk = require("chalk");
var browserify = require("browserify");
@kalharbi
kalharbi / zookeeper-solr-cloud.md
Last active February 22, 2022 02:58
Setting up an external Zookeeper Solr Cluster

Setting up an external Zookeeper Solr Cluster

This is a step by step instruction on how to create a cluster that has three Solr nodes running in cloud mode. These instructions should work on both a local cluster (for testing) and a remote cluster where each server runs in its own physical machine. This was tested on Solr version 5.4.1 and Zookeeper version 3.4.6

Installing Solr and Zookeeper

  • Download and extract Solr:
    • curl -O http://archive.apache.org/dist/lucene/solr/5.5.3/solr-5.5.3.tgz
    • mkdir /opt/solr
@kalharbi
kalharbi / httprouter-middleware-example.go
Last active May 27, 2022 01:42
Example of using a middleware with [httprouter](https://github.com/julienschmidt/httprouter)
package main
import (
"fmt"
"github.com/julienschmidt/httprouter"
"log"
"net/http"
)
// The type of our middleware consists of the original handler we want to wrap and a message
@kalharbi
kalharbi / folder_splitter.py
Created August 29, 2016 21:37 — forked from zupo/folder_splitter.py
Split a folder with many files into subfolders with N files.Usage: python folder_splitter.py path/to/target/folder
# -*- coding: utf-8 -*-
# @author: Peter Lamut
import argparse
import os
import shutil
N = 500 # the number of files in seach subfolder folder