Skip to content

Instantly share code, notes, and snippets.

View tonyspiro's full-sized avatar
🚀
Building and shipping

Tony Spiro tonyspiro

🚀
Building and shipping
View GitHub Profile
@tonyspiro
tonyspiro / gist:de4195fa81e68ed80f77
Last active August 29, 2015 14:04
Here’s a cool function that I use quite often. It looks for two different strings, a beginning and end string, from the original string and returns the middle remainder. Super useful if you do a lot of get_file_contents() and API coding. Check it out:
<?php
function getBetween($content,$start,$end){
$r = explode($start, $content);
if (isset($r[1])){
$r = explode($end, $r[1]);
return $r[0];
}
return '';
}
?>
@tonyspiro
tonyspiro / gist:490962be30a67af923de
Created March 2, 2015 22:43
Curl Get, Post, Put and Delete in PHP
<?php
class Curl {
public function get($url){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
@tonyspiro
tonyspiro / Setup.md
Last active August 29, 2015 14:21 — forked from suvozy/Setup.md
import React from 'react'
import Cosmic from 'cosmicjs'
const config = {
bucket: {
slug: 'next-app'
}
}
export default class extends React.Component {
static async getInitialProps({ req }) {
return new Promise((resolve, reject) => {
{
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "next build; NODE_ENV=production node server.js"
},
"dependencies": {
"axios": "^0.16.2",
"express": "^4.16.2",
"lodash": "^4.17.4",
import axios from 'axios'
import _ from 'lodash'
import Footer from './partials/footer'
import Header from './partials/header'
import helpers from '../helpers'
import config from '../config'
export default class extends React.Component {
static async getInitialProps({ req }) {
const query = `{
const gql_query = `{
objects(bucket_slug: "${config.bucket.slug}") {
type_slug
slug
title
content
metadata
created_at
}
}`
import React, { Component } from 'react';
import './App.css';
class App extends Component {
render() {
return (
<div className="App">
<img style={{ width: '100%' }} src="https://thecatapi.com/api/images/get?format=src&type=jpg"/>
</div>
);
import React from 'react'
import ReactDOM from 'react-dom'
import axios from 'axios'
class App extends React.Component {
constructor(props) {
super(props)
this.state = {
cosmic: null,
loading: true
}
@tonyspiro
tonyspiro / authenticate.js
Last active January 16, 2018 21:01
Cosmic JS NPM module - Authenticate
const Cosmic = require('cosmicjs')()
Cosmic.authenticate({
email: 'you@youremail.com',
password: 'yourpassword'
}).then(data => {
console.log(data)
}).catch(err => {
console.log(err)
})