Skip to content

Instantly share code, notes, and snippets.

View motyar's full-sized avatar
🟢
I may be slow to respond.

Motyar motyar

🟢
I may be slow to respond.
View GitHub Profile
@motyar
motyar / cache.php
Created August 11, 2018 11:34
Simple caching with PHP
<?php
// define the path and name of cached file,
$cachefile = 'cache/'.urlencode($_SERVER['REQUEST_URI']).'.txt';
// define how long we want to keep the file in seconds.
//$cachetime = 60*60*24;
$cachetime = 4;
// Check if the cached file is still fresh. If it is, serve it up and exit.
if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
<h1>Hello</h1>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Test js-yaml</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/3.11.0/js-yaml.min.js"></script>
<script type="text/javascript">
// YAML string to Javascript object
@motyar
motyar / db.php
Last active December 23, 2017 11:47
PHP database class.
<?php
class db {
var $host;
var $db_name;
var $username;
var $password;
var $res;
var $query;
An array, slice, or map composite literal of the form:
[]T{T{}, T{}}
will be simplified to:
[]T{{}, {}}
A slice expression of the form:
s[a:len(s)]
will be simplified to:
s[a:]
@motyar
motyar / gist:9e45e8270c2d2614bfa96ace886ef392
Created May 26, 2017 02:48
Verifying that "motyar.id" is my Blockstack ID. https://onename.com/motyar
Verifying that "motyar.id" is my Blockstack ID. https://onename.com/motyar
@motyar
motyar / login.php
Last active August 10, 2018 12:12
Login with Facebook ( In 20 lines of PHP code )
<?php
// Set $apiVersion, $apiSecret, $redirectUrl, and $scope etc here.
if($_GET['logout']!=""){
session_destroy();
exit("Logged out");
}
if($_GET['code']!=""){
$accessData = json_decode(file_get_contents("https://graph.facebook.com/".$apiVersion."/oauth/access_token?client_id=".$appId."&redirect_uri=".$redirectUrl."&client_secret=".$appSecret."&code=".trim($_GET['code'])),true);
$userInfo = json_decode(file_get_contents("https://graph.facebook.com/v2.7/me?fields=email,id,name&access_token=".$accessData['access_token']),true);
$_SESSION['access'] = $userInfo;
@motyar
motyar / events.php
Created August 23, 2016 02:24
Slack API event handler in PHP
<?php
header('Content-Type: application/x-www-form-urlencoded');
$entityBody = file_get_contents('php://input');
echo $entityBody;
// DO things with Slack API + $entityBody HERE!
?>
package main
import(
"flag"
"fmt"
"net/http"
"strings"
"io/ioutil"
"encoding/json"
"gopkg.in/mgo.v2/bson"