Skip to content

Instantly share code, notes, and snippets.

<?php
$string="
Спишется 50,26р. Пароль 6675
Перевод на счет 41001830685343";
interface IConfirmationSMS {
public function setConfirmationCode($confirmation_code);
public function getConfirmationCode();
@num8er
num8er / FileSearch.js
Last active April 25, 2018 20:28
Recursive search for files by filename in nested directories
const
fs = require('fs'),
path = require('path'),
EventEmitter = require('events');
class FileSearch extends EventEmitter {
constructor(filename, startDir) {
super();
this._filename = filename;
@num8er
num8er / catchAccessToken.js
Last active June 10, 2017 16:00
Middleware for ExpressJS to catch access token and attach to request context
'use strict';
module.exports = (req, res, next) => {
const [left, right] = req.headers.authorization ? req.headers.authorization.split(' ') : [];
if(left === 'Bearer') {
req.accessToken = right;
return next();
}
req.accessToken = [
/*
const originalText = 'Hello World';
const widgets = [
{position: 2, text: '111'},
{position: 4, text: '222'},
{position: 6, text: '333'}
];
Given text and widgets, need to inject widget text in positions.
@num8er
num8er / methods.swift
Last active August 15, 2019 01:18
Sending push notification using OneSignal API where title and content passed from iOS app as json body
func panic() {
let url = URL(string: "https://mywebsite.com/send.php")!
let parameters = ["title": "Some title", "content": "Some content"]
let body = try! JSONSerialization.data(withJSONObject: parameters, options: [])
let request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = body
const config = require('./config.json');
(async () => {
for (let i = 0; i < config.serverList.length; i++) {
const {serverIp, serverPort} = config.serverList[i];
const serverInfo = await getServerInfo(serverIp, serverPort);
if (serverInfo && serverInfo.constructor.name === 'Object') {
config.serverList[i] = {...config.serverList[i], ...serverInfo};
}
}
@num8er
num8er / match.php
Last active November 27, 2019 07:18
Matching substrings between wrappers (with unicode chars in input)
<?php
function matchStringsBetweenWrappers($string, $start, $end) {
// preserving symbols from being removed
$preserveDashPlaceholder = md5($string.'1');
$string = str_replace('-', $preserveDashPlaceholder, $string);
$preserveQuotePlaceholder = md5($string.'2');
$string = str_replace("'", $preserveQuotePlaceholder, $string);
$preserveWildcardPlaceholder = md5($string.'3');
$string = str_replace('*', $preserveWildcardPlaceholder, $string);
$preserveExclamationPlaceholder = md5($string.'4');
<?php
function matchStringsBetweenWrappers($string) {
preg_match_all('/\[N\](.*?)\[\/N\]/u', $string, $matches);
array_walk($matches[0], function(&$item) {
$item = trim($item);
});
return $matches;
}
@num8er
num8er / match.php
Last active December 3, 2019 08:37
WrapperMatcher (matching anything between opening and closing patterns)
<?php
class WrapperMatcher {
private $startPattern = 'N_';
private $endPattern = '_N';
/**
* WrapperMatcher constructor.
*
@num8er
num8er / stdout
Last active December 4, 2019 01:42
Some text N_abc_New_New_New_N! other text N_ghi_jkl_N and other text:;.#{}()[]N_abc_New_N.!@
Немного текста abc_New_New_New ! другой текст ghi_jkl и другой текст:;. # {} () [] abc_New ! @
Some text N_abc_New_New_New_N! other text N_ghi_jkl_N and other text:;.#{}()[]N_abc_New_N.!@
Lego_New New_Friends_New Lego_New
---------
Some text N_abc_New_New_New_N! other text N_ghi_jkl_N and other text:;.#{}()[]N_abc_New_N.!@
Du texte abc_New_New_New ! autre texte ghi_jkl et autre texte:;. # {} () [] abc_New ! @
---------