Skip to content

Instantly share code, notes, and snippets.

@usmansaleem
usmansaleem / instructions.txt
Last active October 12, 2019 18:13
Notes on building Firebird 2.5.4 on Alpine Linux (in docker)
apk add --no-cache --virtual=build-dependencies build-base ncurses-dev icu-dev tar
apk add --no-cache --virtual=build-dependencies --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ shadow
mkdir /work && cd /work
wget -O firebird-source.tar.bz2 http://downloads.sourceforge.net/project/firebird/firebird/2.5.4-Release/Firebird-2.5.4.26856-0.tar.bz2
tar --strip=1 -xf firebird-source.tar.bz2
#Patch rwlock.h (this has been fixed in later release of firebird 3.x)
sed -i '194s/.*/#if 0/' src/common/classes/rwlock.h
@usmansaleem
usmansaleem / auth-guard.service.ts
Last active October 19, 2016 04:58
Angular 2 AuthGuard
import { Injectable } from '@angular/core';
import { Router, CanActivate } from '@angular/router';
import {LoginService} from "./login/login.service";
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private router: Router,
private loginService: LoginService) { }
@usmansaleem
usmansaleem / login.service.ts
Created October 19, 2016 04:55
Angular2 Login Service
import {Injectable} from "@angular/core";
import {Http, Headers, Response} from "@angular/http";
import {Observable} from "rxjs";
import "rxjs/add/operator/map";
/**
* Login Service to obtain access_token and refresh_token.
*/
@Injectable()
export class LoginService {
@usmansaleem
usmansaleem / JwtHttpClient.ts
Created October 19, 2016 04:57
Angular2: Jwt Http Client Wrapper
import {Injectable} from "@angular/core";
import {Http, Headers, RequestOptionsArgs, Response, RequestMethod, RequestOptions, Request} from "@angular/http";
import {LoginService} from "../login/login.service";
import {Observable} from "rxjs";
/**
* JwtHttpClient is a wrapper over Angular Http. It appends JWT header for authentication.
*/
@Injectable()
export class JwtHttpClient {
@usmansaleem
usmansaleem / rpi2vpngateway.md
Last active March 3, 2023 11:23
Raspberry pi as PP2P vpn gateway

Goal

In Progress

Use Raspberry PI 2 as a PP2P VPN gateway so that devices on the network can be configure to use PI as gateway which should direct the internet traffic through VPN.

Setup

  • Modify main router to issue DHCP address so that PI can be assigned an IP address outside the range.
  • Connect PI using ethernet cable. WIFI may also be used, however, following instructions assume eth.
  • Setup PI with static IP address. Modify /etc/dhcpcd.conf with following contents (192.168.1.2 is PI ip address, 192.168.1.1 is the WAN router IP address):
@usmansaleem
usmansaleem / heardoc.md
Created December 15, 2016 00:18
Heardoc example (Writing contents to a file from shell)
cat << EOF > /somefile
These contents will go into file.
EOF
@usmansaleem
usmansaleem / .gitconfig
Created May 30, 2017 21:12
git alias for working with multiple repos from parent directory. Usage 'git all pull'.
[alias]
all = "!sh -c \"find . -mindepth 1 -maxdepth 1 -type d -print -exec git -C {} $1 \\;\" -"
@usmansaleem
usmansaleem / sample_multiline.yml
Created September 4, 2017 23:03
multiline docker environment variable (via docker compose)
environment:
SERVER_NAME: "myserver.doma.in"
# Dummy key, cert
SSL_KEY: |-
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQD272jYrLm8Ph5QpMWFcWUO9Ua1EviykalP+tkMIg12yZ3GvezF
y8aayxdztB5vu68jqMeg6mOJlscWqFUhmAxj4mDknYenVzVX2CKzCgHlGninTKxY
61rXDaDZVpSZ+XIESJkaB0z9HHYtrSLr0coKmq4cT5TRptOnkpDlJxIRaQIDAQAB
AoGATcTYoGTFmiN2KK+8BWrRCQT2X9C5woNdb3LxKIEQ/HhC2HS4PRMQWW/c0vPH
IilZ30EoneUztAFochpRtWLNg4lJoLy04X/eNjEiC/imp0KSwWXmnuLhDcWcb0+M
@usmansaleem
usmansaleem / data.json
Last active October 31, 2019 02:51
The data for blog at usmans.info
[ {
"id" : 186,
"urlFriendlyId" : "tcp_client_using_vertx_kotlin_gradle",
"title" : "TCP Client using Vertx, Kotlin and Gradle build",
"description" : "Step by Step guide to create simple TCP client using Vertx, Kotlin and Gradle",
"body" : "<p>As part of my hobby project to control RaspberryPi using Google Home Mini and/or Alexa, I wanted to write a very simple TCP client that keeps a connection open to one of my custom written server in cloud (I will write another blog post to cover the server side on a later date). The requirement of the client is to send a shared secret upon connecting and then keep waiting for message from server. Vert.x, Kotlin and Gradle allow rapid development of such project. The generated jar can be executed on Raspberry Pi. These steps outline the project setup and related source code to showcase a Vert.x and Kotlin project with Gradle.</p>\n<h2>Project Directory Structure</h2>\n<p>From command line (or via Windows Explorer, whatever you prefer to use) create a directory
@usmansaleem
usmansaleem / gist:6926ad2ddc952b9d34050efa91e83048
Last active November 16, 2017 05:27
Embedding gist with Angular 1
blogApp.directive('gistDirective', function() {
return function(scope, element, attrs) {
scope.$watch('blogItem', function(){
angular.element('[data-gist-id]').gist();
});
}
});
//then