Skip to content

Instantly share code, notes, and snippets.

View riyadhalnur's full-sized avatar
🥚

Riyadh Al Nur riyadhalnur

🥚
View GitHub Profile
@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
@riyadhalnur
riyadhalnur / redraw.go
Last active January 9, 2020 04:23
Redraw a transparent PNG into one with an opaque background. This particular code will redraw with a white background.
package main
import (
"image"
gcolor "image/color"
"image/draw"
"github.com/go-playground/colors"
)
func redrawImage(imgBytes []byte) error {
@riyadhalnur
riyadhalnur / convert.sh
Created December 3, 2019 04:34
GhostScript Conversions
# Convert JPG to PDF
gs -sPAPERSIZE=a4 -sDEVICE=pdfwrite -o output.pdf /usr/share/ghostscript/9.27/lib/viewjpeg.ps -c "(input.jpg) viewJPEG"
# Convert PDF to JPG
gs -sDEVICE=jpeg -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r300 -o output.jpg input.pdf
# Convert PDF to JPG, only 1st page
gs -sDEVICE=jpeg -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dFirstPage=1 -dLastPage=1 -r300 -o output.jpg input.pdf
@riyadhalnur
riyadhalnur / nodejs-ami.json
Created July 7, 2017 04:26
AWS AMI build config for Packer. Install NodeJS using NVM and the latest version of NPM.
{
"variables": {
"aws_access_key": "",
"aws_secret_key": ""
},
"builders": [{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"region": "ap-southeast-1",
@riyadhalnur
riyadhalnur / git_pull_recursive.sh
Last active September 7, 2018 02:49
Recurses a parent directory to do git pulls inside each repo/sub folder
#!/bin/bash
trap 'echo "Wait for the script to finish"' SIGINT SIGTERM EXIT
# Recurses a directory to do git pulls in each repo folder
BASEDIR=/Users/test/go/src/github.com
for dir in "$BASEDIR"/*
do
if [[ -d "$dir" ]]; then
@riyadhalnur
riyadhalnur / .tmux.conf
Last active August 21, 2018 04:29
TMUX Conf
set -g mouse on
set -g @plugin 'jimeh/tmux-themepack'
set -g @themepack 'basic'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @plugin 'tmux-plugins/tmux-prefix-highlight'
run '~/.tmux/plugins/tpm/tpm'
@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 / 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 / token.js
Created April 7, 2017 07:22
Extend ember-simple-auth-token to check for more information
import Ember from 'ember';
import Base from 'ember-simple-auth-token/authenticators/token';
export default Base.extend({
authenticate(credentials, headers) {
return new Ember.RSVP.Promise((resolve, reject) => {
const data = this.getAuthenticateData(credentials);
this.makeRequest(data, headers).then(response => {
if (response.data && response.data.role === 'admin') {
@riyadhalnur
riyadhalnur / form_data.py
Created November 10, 2016 09:46
Retrieve the data from Google Forms that are saved to a Google Spreadsheets file
import gspread
from oauth2client.service_account import ServiceAccountCredentials
SCOPE = ['https://spreadsheets.google.com/feeds']
# The key file can be downloaded from Google Developer Console
KEY = 'yourkey.json'
# Authenticate using your key file
credentials = ServiceAccountCredentials.from_json_keyfile_name(KEY, SCOPE)