Skip to content

Instantly share code, notes, and snippets.

View mfyz's full-sized avatar
✌️

Mehmet Fatih Yıldız mfyz

✌️
View GitHub Profile
@mfyz
mfyz / convert.php
Last active December 15, 2015 00:49
html to pdf conversion using doc converter api
<?php
//set POST variables
$url = 'http://c.docverter.com/convert';
$fields = array('from' => 'html',
'to' => 'pdf',
'input_files[]' => "@/".realpath('input.html').";type=text/html; charset=UTF-8",
);
$ch = curl_init();
@mfyz
mfyz / social_counts.php
Created March 24, 2013 04:04
Getting social (facebook, twitter, +1) counts of a url via php
<?php
function get_tweets($url) {
$json_string = file_get_contents('http://urls.api.twitter.com/1/urls/count.json?url=' . $url);
$json = json_decode($json_string, true);
return intval( $json['count'] );
}
function get_likes($url) {
@mfyz
mfyz / url.php
Created April 9, 2013 04:39
php update url variables
<?
function update_url($_data, $url = NULL){
if (!$url) $url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$_url = parse_url($url);
if (isset($_url['query']) AND $_url['query']) parse_str($_url['query'], $_params);
else $_params = array();
$_updated_params = array_merge($_params, $_data);
@mfyz
mfyz / capture.js
Last active August 29, 2015 13:57
Take snapshot of a webpage with phantomjs
// run this with phantomjs
//create new webpage object
//var page = new WebPage();
var page = require('webpage').create();
//load the page
page.open('http://mfyz.com', function (status) {
//fire callback to take screenshot after load complete
page.render('mfyz.png');
@mfyz
mfyz / counter.php
Created March 30, 2014 00:54
Simple Image Counter
<?php
// sample: <img src="counter.php?counter=total_visits">
function hex2rgb($color){
$color = str_replace('#', '', $color);
if (strlen($color) != 6){ return array(0,0,0); }
$rgb = array();
for ($x=0;$x<3;$x++){
$rgb[$x] = hexdec(substr($color,(2*$x),2));
@mfyz
mfyz / social_counts.html
Created March 30, 2014 03:22
Get social counts via javacript
<!doctype html>
<html>
<head>
<title>Page</title>
</head>
<body>
<script type="text/javascript" charset="utf-8">
// Tiny object for getting counts
var socialGetter = (function() {
/* just a utility to do the script injection */
@mfyz
mfyz / resize_preview.html
Created April 8, 2014 21:49
HTML5 FileReader + canvas resizer to resize & preview before upload an image using jquery.
<!DOCTYPE html>
<html>
<head>
<title>Angular HTML5 Preview, Crop And Upload</title>
<style>
body {
padding: 50px;
font: 16px Helvetica;
}
@mfyz
mfyz / retina.less
Created May 22, 2014 21:06
Improved retina.less for compiling retina backgrounds with an existing media query.
// retina.less
@highdpi: ~"# (-webkit-min-device-pixel-ratio: 1.5), # (min--moz-device-pixel-ratio: 1.5), # (-o-min-device-pixel-ratio: 3/2), # (min-resolution: 1.5dppx)";
.retinaBg(@path, @w: auto, @h: auto, @prefix: _) {
background-image: url(@path);
@at2x_path: ~`@{path}.replace(/\.\w+$/, function(match) { return "@2x" + match; })`;
@final_media: ~`"@{highdpi}".replace(/(\#)/g, function(match) { return ("@{prefix}".length > 1 ? " @{prefix} and " + match : ""); }).replace(/\#/g, '')`;
@mfyz
mfyz / website.js
Last active August 29, 2015 14:24
express basic http auth
var express = require('express');
var app = express();
var fs = require('fs');
var auth = express.basicAuth(function(user, pass) {
return user === 'test' && pass === 'pass';
});
app.get('/', auth, function(req, res) {
res.setHeader('Content-Type', 'text/html');
@mfyz
mfyz / framer-tap-fix.js
Last active September 25, 2015 14:56
Framerjs scrollcomponent scroll and tap conflict solution.
var tapStartX, tapStartY;
list_item.on(Events.TouchStart, function(e){ tapStartX = e.pageX; tapStartY = e.pageY; });
list_item.on(Events.TouchEnd, function(e){
if (Math.abs(e.pageX - tapStartX) < 20 && Math.abs(e.pageY - tapStartY) < 20) {
// real tap happened
}
});