Skip to content

Instantly share code, notes, and snippets.

View onliniak's full-sized avatar

Rafael Pszenny onliniak

View GitHub Profile
@onliniak
onliniak / check.php
Last active November 28, 2019 18:16
JS Fetch API → send POST and display response
<?php
$json = file_get_contents('php://input');
$obj = json_decode($json, true);
var_dump($obj);
@onliniak
onliniak / index.js
Created November 25, 2019 21:56
WordPress AJAX login/register
//jQuery edition
jQuery("#login_button").click(function(){
var email = document.getElementById("username").value;
var pass = document.getElementById("Pass").value;
var secu = document.getElementById("security").value;
jQuery.ajax({
type: 'POST',
url: 'login.php',
data: {username: email, password: pass, security: secu},
@onliniak
onliniak / index.php
Last active November 10, 2019 14:28
Non visible checkbox with few POST parameters.
<?php $myposts = get_posts( $args ); ?>
<form id="formName">
<?php
foreach ( $myposts as $service ) {
$service_lenght = get_post_meta($service->ID, 'Lenght');
?>
<label>
<h1><?php echo $service->post_title ?> </h1>
<img src="<?php get_the_post_thumbnail_url($service->ID); ?>" />
@onliniak
onliniak / index.php
Created November 10, 2019 13:57
Connect any php file to WordPress functions/database
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/wp-config.php';
global $wpdb;
$wpdb->get_var('Single row');
$result = $wpdb->get_results('Multiple rows');
foreach ( $result as $row )
{
@onliniak
onliniak / app.rb
Created October 4, 2019 08:06
Rack session
session[:key] = 'value'
request.session['key']
@onliniak
onliniak / form.html
Created September 29, 2019 16:27
Javascript params from input
<input type="email" name="user">
<input type="password" name="key">
<input name="submit" type="submit" onclick="login()">
@onliniak
onliniak / test.js
Created September 25, 2019 13:41
Modern js → multi-lines, regex and optional semicolons.
//you should replace ä with any non-usable character.
test = `
ä
.
heloo
ä
`.replace(/(\s{4})/, "START")
.replace(".", "DISPLAY")
.replace(/(\s{2})/, "STOP")
.replace(/ä/g, "")
@onliniak
onliniak / composer.json
Created September 18, 2019 13:28
Phug templates partial rendering
{
"require":{
"phug/phug":"^0.3.2"
}
}
@onliniak
onliniak / .htaccess_public
Last active September 16, 2019 14:14
[PHP] simple MVC router and public directory (Appache)
#public/.htaccess
RewriteEngine On
RewriteBase /public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
@onliniak
onliniak / app.rb
Last active September 29, 2019 17:41
Slim template engine in Roda framework
class Test < Roda
plugin :render, engine: 'slim'
route do |r|
r.get 'test' do
view :hello
end
r.root do
'Home, Sweet Home'
end