Skip to content

Instantly share code, notes, and snippets.

@kopiro
kopiro / oauth-client.php
Last active February 18, 2016 15:33
PHP Oauth Client parser
<?php
Route::get('oauth/client', function() {
$url = OAUTH_DOMAIN . '/oauth/access_token';
$post = [
'grant_type' => 'authorization_code',
'code' => Input::get('code'),
'redirect_uri' => OAUTH_REDIRECT_URI,
'client_id' => OAUTH_ID,
@kopiro
kopiro / lol.js
Created February 18, 2016 15:28
Generate a natural fingered-base entropy MD5
var Leap = require('/usr/local/lib/node_modules/leapjs');
var Crypto = require("crypto");
var hash = Crypto.createHash("md5");
var hashCount = 0;
Leap.loop(function(frame){
if (frame.hands && frame.hands.length > 0) {
var h = frame.hands[0];
@kopiro
kopiro / facebook-ticker.js
Last active February 27, 2019 09:12
Filter Facebook ticker stories with a RegEx
(function() {
var filterName = new RegExp(prompt("Insert the regex"), 'i');
if (!filterName) {
return alert('Invalid regex');
}
var MAX_ITERATIONS = 500;
var $profileNode = document.querySelector('[title="Profile"] > span');
@kopiro
kopiro / fast-wp-setting.php
Last active January 19, 2016 09:03
Fast add setting in WP
<?php
add_action( 'admin_init', function() {
$option = 'test';
register_setting('general', $option, 'esc_attr');
add_settings_field($option, 'Test', function() use ($option) {
$value = get_option($option, '');
echo '<input type="text" id="' . $option . '" name="' . $option . '" value="' . esc_attr($value) . '" />';
}, 'general');
});
@kopiro
kopiro / call_and_apply.js
Created November 30, 2015 12:04
Call and Apply replica in Pure JS
function x(a,b,c) {
console.log('Called X:', a,b,c);
}
Function.prototype._call = function() {
var first = Array.prototype.shift.apply(arguments);
this.apply(first, arguments);
};
Function.prototype._apply = function() {
@kopiro
kopiro / widgets.md
Last active February 29, 2016 08:31
Titanium modules/Widget
@kopiro
kopiro / cors-proxy-wp.php
Last active December 16, 2017 15:44
WP Proxy in PHP for CORS
<?php
if (preg_match("/^\/proxy\/(.+)$/", $_SERVER['REQUEST_URI'], $match)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.com/" . $match[1]);
curl_setopt($ch, CURLOPT_USERAGENT, 'Proxy');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
die(curl_exec($ch));
@kopiro
kopiro / renderer.js
Created August 24, 2015 10:48
PhantomJS Renderer
#!/usr/bin/env phantomjs
var args = require('system').args;
var URL = args[1];
var FILE = args[2];
var W = args[3];
var H = args[4];
if (URL && FILE && W && H) {
@kopiro
kopiro / wp_asset.php
Last active August 29, 2015 14:25
Function wp_asset
<?php
function wp_asset($type, $key, $url, $deps = null) {
call_user_func("wp_deregister_$type", $key);
call_user_func("wp_enqueue_$type", $key, $url, $deps, filemtime(__FILE__));
}
// Usage:
// wp_asset('script', 'jquery', '/assets/js/jquery.js', []);
@kopiro
kopiro / event-titanium.js
Last active August 29, 2015 14:21
Handle event listeners in Titanium
element._addEventListener = element.addEventListener;
element._removeEventListener = element.removeEventListener;
element.addEventListener = function(e,c) {
element._listeners[e] = element._listeners[e] || [];
element._listeners[e].push(c);
element._addEventListener(e,c);
};
element.removeEventListener = function(e,c) {