Skip to content

Instantly share code, notes, and snippets.

View riyadhalnur's full-sized avatar
🥚

Riyadh Al Nur riyadhalnur

🥚
View GitHub Profile
@riyadhalnur
riyadhalnur / mongo_dump.sh
Last active February 4, 2016 07:14
Take a snapshot of your MongoDB using shell script and upload to S3
#!/bin/bash
MONGO_DATABASE=""
APP=""
TIMESTAMP=`date +%F-%H%M`
MONGODUMP_PATH="/usr/bin/mongodump"
BACKUPS_DIR="/home/me/backups/$APP"
BACKUP_NAME="$APP-$TIMESTAMP"
@riyadhalnur
riyadhalnur / strip_vowels.py
Created December 2, 2015 10:05
Strip all vowels from a given string
def anti_vowel(text):
vowels = ['a','e','i','o','u']
result = []
for i in range(len(text)):
if text[i].lower() not in vowels:
result.append(text[i])
return ''.join(result)
@riyadhalnur
riyadhalnur / reverse.py
Created December 2, 2015 09:53
Reverse a string in Python
def reverse(text):
reversed = []
for i in range(len(text)):
reversed.append(text[-(i+1)])
return ''.join(reversed)
@riyadhalnur
riyadhalnur / uniqueValuesArray.js
Last active November 29, 2015 13:04
Get the number of occurrences of every item in an array
// sample -> [ 1, 2, 1, 'a', [ 'd', 5, 6 ], 'A', 2, 'b', 1, 'd' ];
// result -> { 1: 3, 2: 2, a: 1...}
function flattenArray (arr, result) {
result = result || [];
for (var i = 0; i < arr.length; i++) {
if (Array.isArray(arr[i])) {
flattenArray(arr[i], result);
} else {
@riyadhalnur
riyadhalnur / keystone.js
Last active November 15, 2017 17:40
Add more options to the express app when using KeystoneJS
var keystone = require('keystone');
var express = require('express');
var body = require('body-parser');
var helmet = require('helmet');
var app = express();
app.use(body.urlencoded({ extended: false }));
app.use(body.json());
app.use(helmet());
@riyadhalnur
riyadhalnur / breeds.txt
Created September 11, 2015 19:59
Count the number of occurrences of each letter of the alphabet in a file
Airedale Terrier, Terrier
Affenpinscher, Toy
Afghan Hound, Hound
Airedale Terrier, Terrier
Akita Inu, Working
Alaskan Malamute, Working
American English Coonhound, Hound
American Eskimo Dog (Miniature), Non-Sporting
American Eskimo Dog (Standard), Non-Sporting
American Eskimo Dog (Toy), Toy
@riyadhalnur
riyadhalnur / nginx.conf
Last active December 20, 2015 10:23
Server config for hosting NodeJS apps behind a NGINX reverse proxy server
server {
listen 443;
server_name mydomain.com www.mydomain.com;
access_log /var/logs/access.log main_timed;
# See https://mozilla.github.io/server-side-tls/ssl-config-generator/ for appropriate SSL settings
ssl on;
ssl_certificate /opt/ssl/site/mydomain.com.crt;
ssl_certificate_key /opt/ssl/site/mydomain.com.key;
add_header Strict-Transport-Security max-age=15768000;
@riyadhalnur
riyadhalnur / inviteCustomers-Spec.js
Created August 11, 2015 17:08
Generate list of customers within 100km of GPS coordinates 53.3381985, -6.2592576. Program reads the full list of customers and outputs the names and user ids of matching customers (within 100km), sorted by user id (ascending).
var should = require('should');
var Invitations = require('./Invitations');
describe('Customers to invite to office', function () {
var invite;
beforeEach(function () {
invite = new Invitations(53.3381985, -6.2592576);
});
@riyadhalnur
riyadhalnur / flattenArray-Spec.js
Last active August 29, 2015 14:27
Flatten nested arrays to an array one level deep
var should = require('should');
var flattenArray = require('./flattenArray.js');
describe('Flatten Nested Arrays', function () {
it('should flatten a nested array', function () {
var testArr = [[1,2,[3]],4];
flattenArray(testArr).should.be.an.Array;
flattenArray(testArr).should.equal([1,2,3,4]);
});
@riyadhalnur
riyadhalnur / wp.py
Last active December 28, 2020 16:51
Script to run queries against a WordPress site using Python. Install the library using `pip install python-wordpress-xmlrpc` before running this script. Run this script in the terminal using `python wp.py`
import sys
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts, GetPost
wp = Client('https://yoursiteaddress.com/xmlrpc.php', 'username', 'password') # update the site address, username and password
# retrives the list of all posts in the blog. Optional: you can supply filters and fields to sort by.
print(wp.call(GetPosts({'post_status': 'publish'})))
# retrives a single post in the blog. Required: postId. Optional: fields
# pass in postId when running this script, e.g python wp.py 1234