Skip to content

Instantly share code, notes, and snippets.

@devfred
devfred / jquery.fk-qr.js
Last active December 21, 2023 10:31
javascript: Generate QR code on the fly
/**
Quick and dirty plugin to generate qr code on the fly
@author Frederick King
**/
(function($, undefined) {
/**
Generate qr code on the fly
@parameter {object} options
**/
$.fn.qrCode = function(options) {
@devfred
devfred / globalEval.js
Created May 18, 2012 16:38
javascript: Evaluate a script in a global context
// Evaluates a script in a global context
// Workarounds based on findings by Jim Driscoll
// http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
// pulled from jquery.core source
var globalEval = function( data ){
if ( data ) {
// We use execScript on Internet Explorer
// We use an anonymous function so that context is window
// rather than jQuery in Firefox
@devfred
devfred / FileGetContents.cs
Last active December 11, 2020 17:55
csharp: Function that acts like PHP's file_get_contents
protected string file_get_contents(string fileName)
{
string sContents = string.Empty;
if (fileName.ToLower().IndexOf("http:") > -1){
// URL
System.Net.WebClient wc = new System.Net.WebClient();
byte[] response = wc.DownloadData(fileName);
sContents = System.Text.Encoding.ASCII.GetString(response);
} else {
@devfred
devfred / gist:9802185560e9b0836a12fe8c8e158cf1
Created August 9, 2020 19:29 — forked from metavida/gist:601087
How to retrieve a Report record via the Haiku LMS API, using C#.
// Based on code from the following sources:
// * http://www.voiceoftech.com/swhitley/index.php/2009/03/twitter-oauth-with-net/
// * http://oauth.googlecode.com/svn/code/csharp/
// Note: if you're using mono the following command will compile this code `gmcs -r:System.Web.dll this_file.cs`
using System;
using System.Security.Cryptography;
using System.Collections.Generic;
using System.Text;
using System.Net;
@devfred
devfred / browser-detect.js
Last active August 7, 2020 23:28
javascript: Browser Detection
(function( undefined ){
/* Apple Device Webkit Browsers */
var isIdevice = /(iPhone|iPod|iPad).*AppleWebKit/i.test(navigator.userAgent);
if (isIdevice){
document.getElementsByTagName('body')[0].className += ' iphone ipod ipad';
}
var isIphone = /(iPhone).*AppleWebKit/i.test(navigator.userAgent);
if (isIphone){
document.getElementsByTagName('body')[0].className += ' iphone';
@devfred
devfred / audio-api-wrapper.ts
Last active February 17, 2020 19:17
Typescript: HTML5 Audio Wrapper for angular2
/**
* @class
* @description
* Wrapper for HTML5 audio.
*/
import {Injectable, NgZone} from 'angular2/core';
import {Observer} from 'rxjs/Observer';
import {Observable} from 'rxjs/Observable';
declare var AudioContext:any;
var UpdateQueryStringParameter = function(uri, key, value) {
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
return uri.replace(re, '$1' + key + "=" + value + '$2');
}
else {
return uri + separator + key + "=" + value;
}
};
@devfred
devfred / Number.prototype.formatMoney.js
Last active April 3, 2018 17:25
javascript: Restrict all number inputs to use only digits, commas, periods
Number.prototype.formatMoney = function(c, d, t){
var
n = this,
c = isNaN(c = Math.abs(c)) ? 2 : c,
d = d == undefined ? "," : d,
t = t == undefined ? "." : t,
s = n < 0 ? "-" : "",
i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
@devfred
devfred / jquery.fk-forecast.js
Last active February 9, 2018 23:36
javascript: Weather forecast jquery plugin
/**
* Weather Forecast Plugin
* Author: Frederick King
*
**/
(function(window, document, $, undefined) {
var api = {
load: function(zip, $elem) {
var self = this;
// XDomain Request for IE8/IE9 :(
@devfred
devfred / nginx.conf
Created November 16, 2016 08:56 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048