Skip to content

Instantly share code, notes, and snippets.

View alpenzoo's full-sized avatar

Narcis Iulian Paun alpenzoo

View GitHub Profile
<?php
/**
* The __halt_compiler() function will stop the PHP compiler when called.
* You can then use the __COMPILER_HALT_OFFSET__ constant to grab the contents of the PHP file after the halt.
* In this example a PHP template is stored after the halt, to allow simple separation of logic from templating.
* The template is stored in a temporary file so it can be included and parsed.
*
* See: https://github.com/bobthecow/mustache.php/blob/dev/src/Mustache/Loader/InlineLoader.php
* http://php.net/manual/en/function.halt-compiler.php
*/
@alpenzoo
alpenzoo / send-fcm.php
Created August 24, 2017 12:21
Firebase FCM from PHP the easy way. Send payload as desired. Returns execution result. Just a gist, no production code.
<?php
$deviceToken = $_POST['dt'];
$body = $_POST['b'];
if (empty($deviceToken)){
die ("nothing to do, no device. exit");
}
#API access key from Google API's Console
define( 'API_ACCESS_KEY', '' );
#prep the bundle
<?php
//create random hash, please notice $6$ as first chars in salt string
$salt = "$6$5e2de398074f9213";
$hash = crypt('pswt1', $salt);
echo $hash;
//mariaDB compatible code: select ENCRYPT('pswt1', CONCAT('$6$', SUBSTRING(SHA(RAND()), -16)));
echo "<hr>";
@alpenzoo
alpenzoo / gist:ffbef7610e7183227afbee8d74a9a07c
Created November 28, 2017 12:25 — forked from jansanchez/gist:6694824
How do I store an array of objects in a cookie with jQuery $.cookie()?
/*
Cookies can only store strings. Therefore, you need to convert your array of objects into a JSON string.
If you have the JSON library, you can simply use JSON.stringify(people) and store that in the cookie,
then use $.parseJSON(people) to un-stringify it.
In the end, your code would look like:
*/
var people = [
{ 'name' : 'Abel', 'age' : 1 },
{ 'name' : 'Bella', 'age' : 2 },
@alpenzoo
alpenzoo / test.js
Created February 7, 2018 13:49 — forked from jmyrland/test.js
Socket-io load test?
/**
* Modify the parts you need to get it working.
*/
var should = require('should');
var request = require('../node_modules/request');
var io = require('socket.io-client');
var serverUrl = 'http://localhost';
@alpenzoo
alpenzoo / git command.markdown
Last active July 6, 2018 12:38 — forked from nasirkhan/git command.markdown
`git` discard all local changes/commits and pull from upstream

git discard all local changes/commits and pull from upstream

git reset --hard origin/master

git pull origin master

To ignore file: git checkout pom.xml

To perform a pull:

@alpenzoo
alpenzoo / 01 create_paper_keyword.sql
Last active March 29, 2018 07:25 — forked from cwerner13/01 create_paper_keyword.sql
RegExp_Split_To_Table: PostgreSQL command to split and trim a text field and create one row for each keyword in the expression
drop table ba_paper_keyword;
create table ba_paper_keyword as
(
select p.id, p.keyword, count(p.keyword) count
from
(select id
, trim (both ';,.:?()"' from regexp_split_to_table(lower(paper.keyword), E'\\\s+')) AS keyword
from paper)p
group by p.id, p.keyword
)
if (window.innerWidth > 640) {
var floatParentNode = document.querySelector('.js-parent');
var floatNode = document.querySelector('.js-float');
var valScrollForFixed = floatParentNode.getBoundingClientRect().top + window.pageYOffset - document.querySelector('.js-header').offsetHeight;
window.addEventListener('scroll', function () {
if (window.innerHeight > floatNode.offsetHeight) {
var windowScrollTop = window.pageYOffset;
var footerTop = document.querySelector('.js-footer').getBoundingClientRect().top + windowScrollTop;
var footerHeight = document.querySelector('.js-footer').clientHeight;
// http://learn.javascript.ru/external-script
function addScript(src){
var script = document.createElement('script');
script.src = src;
script.async = false; // чтобы гарантировать порядок
document.head.appendChild(script);
}
addScript('1.js'); // загружаться эти скрипты начнут сразу
@alpenzoo
alpenzoo / debounce
Created March 29, 2018 07:31 — forked from oleksapro/debounce
js
// http://frontender.info/essential-javascript-functions/
// Возвращает функцию, которая не будет срабатывать, пока продолжает вызываться.
// Она сработает только один раз через N миллисекунд после последнего вызова.
// Если ей передан аргумент `immediate`, то она будет вызвана один раз сразу после
// первого запуска.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {