Skip to content

Instantly share code, notes, and snippets.

View typerandom's full-sized avatar

Robin Orheden typerandom

View GitHub Profile
@typerandom
typerandom / gist:18308e43783e5ade6c5c
Created July 16, 2014 05:21
userapp-facebook-find-connection
$client = User::getClient();
$facebook_id = null;
$connection_result = $client->oauth->connection->search(array(
"user_id" => "self"
));
foreach($connection_result->items as $connection){
if($connection->provider_id == 'facebook'){
@typerandom
typerandom / time-elapsed-approximation-format.js
Created April 23, 2012 11:48
Convert/format a date to the highest time unit.
function getApproximateElapsedTime(date) {
var timeDelta = new Date().getTime() - date.getTime(); // ms
var map = [
{ unit: 1000, singular: "%d second", plural: "%d seconds" },
{ unit: 60, singular: "%d minute", plural: "%d minutes" },
{ unit: 60, singular: "%d hour", plural: "%d hours" },
{ unit: 24, singular: "%d day", plural: "%d days" },
{ unit: 29.53, singular: "%d month", plural: "%d months" }, // Avg. days per month
{ unit: 12, singular: "%d year", plural: ">%d years" }
@typerandom
typerandom / csharp-send-email-native.cs
Created September 19, 2012 18:20
Send Email natively with C#/.NET
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Mail;
namespace Comfirm.Examples.Native
{
class Program
@typerandom
typerandom / csharp-send-email-alphmail.cs
Created September 19, 2012 18:57
Send Email through AlphaMail using C#/.NET
using System;
using Comfirm.AlphaMail.Services.Client;
using Comfirm.AlphaMail.Services.Client.Entities;
namespace Comfirm.Examples.AlphaMail
{
class Person
{
public int Id { get; set; }
public string UserName { get; set; }
@typerandom
typerandom / comlang-template-for-sending-email-with-csharp
Created September 20, 2012 12:21
Comlang Template for Sending Email with AlphaMail using C#/.NET
<html>
<body>
<b>Name:</b> <# payload.FirstName " " payload.LastName #><br>
<b>Date of Birth:</b> <# payload.DateOfBirth #><br>
<# if (payload.Id != null) { #>
<a href="http://company.com/sign-up">Sign Up Free!</a>
<# } else { #>
<a href="http://company.com/login?username=<# urlencode(payload.UserName) #>">Sign In</a>
<# } #>
@typerandom
typerandom / php-mail-html-mime.php
Created November 21, 2012 16:39
PHP mail-function - HTML mime example
<?php
// multiple recipients
$to = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '
@typerandom
typerandom / php-mail-simple.php
Created November 21, 2012 17:28
PHP mail-function - Simple example
<?php
// to, subject, body
mail('test@test.com', 'My Subject', "My awesome body text");
?>
@typerandom
typerandom / phpmailer-simple.php
Created November 21, 2012 17:25
PHPMailer - Simple example
<?php
require 'class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->IsHTML(true);
$mail->Host = 'smtp1.example.com';
$mail->SMTPAuth = true;
@typerandom
typerandom / swiftmailer-simple.php
Created November 21, 2012 20:39
Swift Mailer - Simple example
<?php
require_once 'lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25)
->setUsername('your username')
->setPassword('your password');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Wonderful Subject')
@typerandom
typerandom / alphamail-simple.php
Created November 21, 2012 20:57
AlphaMail Example
<?php
include_once("comfirm.alphamail.client/emailservice.class.php");
$email_service = AlphaMailEmailService::create()
->setServiceUrl("http://api.amail.io/v1")
->setApiToken("YOUR-ACCOUNT-API-TOKEN-HERE");
$notification = array(
"user" => array(
"name" => "John"