Skip to content

Instantly share code, notes, and snippets.

@raksa
raksa / php7<->CryptoJS.php
Created September 25, 2018 09:29
encrypt and decrypt by PHP7, encrypt and decrypt by JS
<?php
const SALT = 'salt';
const IV = '1111111111111111';
const ITERATIONS = 999;
function userPHPEncrypt($passphrase, $plainText)
{
$key = \hash_pbkdf2("sha256", $passphrase, SALT, ITERATIONS, 64);
$encryptedData = \openssl_encrypt($plainText, 'AES-256-CBC', \hex2bin($key), OPENSSL_RAW_DATA, IV);
return \base64_encode($encryptedData);
}
@pixelbrackets
pixelbrackets / api.php
Last active October 27, 2023 19:13
Simple PHP script to test and use cURL
<?php
/**
* Simple request response script
*
* Point you cURL request to this script to see all incoming data
*/
echo '*API*'. PHP_EOL;
@statickidz
statickidz / nearby-coordinates.sql
Last active January 31, 2024 20:31
Ordering with SQL by nearest latitude & longitude coordinates (MySQL & SQLite)
---
METHOD 1
This should roughly sort the items on distance in MySQL, and should work in SQLite.
If you need to sort them preciser, you could try using the Pythagorean theorem (a^2 + b^2 = c^2) to get the exact distance.
---
SELECT *
FROM table
ORDER BY ((lat-$user_lat)*(lat-$user_lat)) + ((lng - $user_lng)*(lng - $user_lng)) ASC
@AFelipeTrujillo
AFelipeTrujillo / addAttendee.php
Last active February 26, 2024 21:28
Use Google Calendar API
<?php
include_once 'google-api-php-client/vendor/autoload.php';
$client = new Google_Client();
$application_creds = 'service-account-credentials.json';
$credentials_file = file_exists($application_creds) ? $application_creds : false;
define("SCOPE",Google_Service_Calendar::CALENDAR);
define("APP_NAME","Google Calendar API PHP");
@robcowie
robcowie / optgroup_filter.js
Created March 31, 2012 19:41
Filter option elements by optgroup based on value of a second select element
$.fn.filterGroups = function( options ) {
var settings = $.extend( {}, options);
return this.each(function(){
var $select = $(this);
// Clone the optgroups to data, then remove them from dom
$select.data('fg-original-groups', $select.find('optgroup').clone()).children('optgroup').remove();
$(settings.groupSelector).change(function(){
@veprbl
veprbl / html5_valid_elements.js
Created August 10, 2011 07:28
TinyMCE valid_elements setting for HTML5
valid_elements : ""
+"@[accesskey|draggable|style|class|hidden|tabindex|contenteditable|id|title|contextmenu|lang|dir<ltr?rtl|spellcheck|"
+"onabort|onerror|onmousewheel|onblur|onfocus|onpause|oncanplay|onformchange|onplay|oncanplaythrough|onforminput|onplaying|onchange|oninput|onprogress|onclick|oninvalid|onratechange|oncontextmenu|onkeydown|onreadystatechange|ondblclick|onkeypress|onscroll|ondrag|onkeyup|onseeked|ondragend|onload|onseeking|ondragenter|onloadeddata|onselect|ondragleave|onloadedmetadata|onshow|ondragover|onloadstart|onstalled|ondragstart|onmousedown|onsubmit|ondrop|onmousemove|onsuspend|ondurationmouseout|ontimeupdate|onemptied|onmouseover|onvolumechange|onended|onmouseup|onwaiting],"
+"a[target<_blank?_self?_top?_parent|ping|media|href|hreflang|type"
+"|rel<alternate?archives?author?bookmark?external?feed?first?help?index?last?license?next?nofollow?noreferrer?prev?search?sidebar?tag?up"
+"],"
+"abbr,"
+"address,"
+"area[alt|coords|shape|href|target<_blank?_self?_top?_parent|ping|media