Skip to content

Instantly share code, notes, and snippets.

View ragingprodigy's full-sized avatar
🏠
Working from home

Oladapo Bernard Omonayajo ragingprodigy

🏠
Working from home
View GitHub Profile
function encodeImage(imageUrl, callback) {
var URL = require('url'),
sURL = imageUrl,
oURL = URL.parse(sURL),
http = require('http');
var request = http.request({method:'GET', path:oURL.pathname, host: oURL.hostname, port:80});
request.end();
@ragingprodigy
ragingprodigy / amazon-s3-upload.js
Created April 12, 2017 01:36
Generate File Upload policy for Amazon s3
'use strict';
var AWS = require('aws-sdk'),
crypto = require('crypto'),
createS3Policy,
getExpiryTime;
getExpiryTime = function () {
var _date = new Date();
return '' + (_date.getFullYear()) + '-' + (_date.getMonth() + 1) + '-' +
(_date.getDate() + 1) + 'T' + (_date.getHours() + 3) + ':' + '00:00.000Z';
@ragingprodigy
ragingprodigy / OORadialGradientView.m
Created April 12, 2017 01:21
Radial Gradient Implementation - Objective C
@implementation OORadialGradientView
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing Code
CGContextRef context = UIGraphicsGetCurrentContext();
// Draw A Gradient from yellow to Orange
NSArray *colors = [NSArray arrayWithObjects:(id)[UIColor yellowColor].CGColor, (id)[UIColor orangeColor].CGColor, nil];
@ragingprodigy
ragingprodigy / read-auto-complete.coffee
Last active March 22, 2016 20:20
Script to set the value of an input field populated using a browser's autocomplete feature
angular.module 'myModule', []
.factory 'inputsWatcher', ( $interval ) ->
INTERVAL_MS = 500
handlers = []
execHandlers = ->
for handler in handlers
handler()
registerInput: (handler) ->
@ragingprodigy
ragingprodigy / superPower.php
Created October 13, 2015 10:24
Determine if an integer Z can be expressed in the form P^Q using PHP
<?php
/**
* Return 1 if $Z can be expressed as on integer raised to the power of another integer
*/
function superPower( $Z) {
$half = (int) sqrt($Z);
for ($x=2; $x<$half; $x++) {
if ($Z % $x == 0) {
@ragingprodigy
ragingprodigy / AppAuth.js
Created December 22, 2014 08:36
AngualrJS Module to help in Web Application authentication (Written in Javascript)
// Generated by CoffeeScript 1.7.1
(function() {
var app = angular.module('AppAuth', [])
app.config([
'$httpProvider', function($httpProvider) {
//Intercept all Out-Going HTTP Requests
$httpProvider.interceptors.push("AuthInterceptor");
@ragingprodigy
ragingprodigy / AppAuth.coffee
Last active August 29, 2015 14:11
AngualrJS Module to help in Web Application authentication
app = angular.module 'AppAuth', []
app.factory 'AuthService', ['$http', 'Session', 'AuthToken', ($http, Session, AuthToken) ->
{
login: (username, password) ->
$http.post('api/v1/users/login/', {
username: username
password: password
}).then (response) ->
AuthToken.set(response.data.records.privateKey) if response.data._meta.status == 'SUCCESS'
@ragingprodigy
ragingprodigy / angular-select2-directive.coffee
Last active August 29, 2015 14:11
AngularJS directive to use the jQuery Select2 plugin
app.directive 'selectPlugin', [ ->
{
restrict: 'A'
link: (scope, elem, attr) ->
angular.element(elem).select2 { placeholder: attr.selectPlugin }
}
]
@ragingprodigy
ragingprodigy / select2_angularjs.coffee
Created December 11, 2014 12:17
Select2 AngularJs directive example with custom query call to append data to the request. Note: Providing ajax settings is not needed (and not used) when query is provided. Left here as a full example.
# The "query" configuration is adapted from this gist: https://gist.github.com/techniq/4609063
.directive 'remoteSelectPlugin', ['$http', ($http) ->
{
restrict: 'A'
link: (scope, elem, attr) ->
angular.element(elem).select2({
placeholder: attr.remoteSelectPlugin
minimumInputLength: 1
query: (options) ->