Skip to content

Instantly share code, notes, and snippets.

View catalint's full-sized avatar
🎯
Focusing

Cătălin Tănăsescu catalint

🎯
Focusing
View GitHub Profile
// Hi Jack https://www.youtube.com/watch?v=f1FV6AELDmA
let jackGotDrunk=[];
jackGotDrunk[197]='OoOPsie'
const AThousandJacks = (JSON.stringify(jackGotDrunk)+'....').replace(/./g,'Jack')
console.log(AThousandJacks)
console.log('Jack got drunk for how many times ?',AThousandJacks.match(/Jack/g).length)
console.log('Only Jack got drunk ?', AThousandJacks.length / "Jack".length === 1000 ? 'Yeee':'Neee')
@catalint
catalint / after.json
Created April 27, 2016 15:58
hapi-swagger performance
{
"tags": [],
"host": "localhost:3000",
"schemes": [
"http"
],
"info": {
"title": "Test API Documentation",
"version": "1.0.0"
},
<link rel="import" href="../components/polymer/polymer.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
height: 100%;
<link rel="import" href="../components/polymer/polymer.html">
<polymer-element name="my-element">
<template>
<style>
#core_header_panel {
width: 300px;
height: 400px;
left: 550px;
@catalint
catalint / xml_parser.php
Last active August 29, 2015 14:01
Simple class to parse BIG xml files without loading them in memory. It parses one tag a time.
$reader = new XMLReaderToSimpleXML();
$reader->open($filePath);
while($package = $reader->nextElement('Package')){
parsePackage($package); // edit this to do the parsing stuff
}
class XMLReaderToSimpleXML extends XMLReader{
function nextElement($tagName){
while($this->read()){
@catalint
catalint / parse.js
Created May 10, 2014 17:25
phantomjs example
var page = new WebPage(),
url = 'http://filipnet.ro',
stepIndex = 0;
page.onConsoleMessage = function (msg, line, source) {
console.log('console> ' + msg);
};
page.onError = function(msg, trace) {
server {
error_log /var/log/nginx/vhost-error_log warn;
access_log /usr/local/apache/domlogs/catalint.ro-bytes_log bytes_log;
listen 8.8.8.8:80;
server_name catalint.ro www.catalint.ro;
location @proxy {
proxy_pass http://8.8.8.8:81;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@catalint
catalint / createvhosts.php
Created April 25, 2014 07:46
Putting nginx in front of the Apache server that comes with Cpanel can be tricky. Bellow is a script that reads the cpanel config files of the accounts and builds nginx server's (similar to Apache vhost) from them. It can also be added to do this automatically when new accounts and domains are registered on the server. The script's coding style …
<?php
$conf='/etc/nginx/vhosts/vhost.conf';
$confFile=fopen($conf,'w');
exec("find /var/cpanel/userdata/* -type f -not -name '*cache*' -not -name '*db' -not -name 'main' -not -name 'vhost*'",$ary);
foreach ($ary as $f){
$fis=file_get_contents($f);
preg_match("@\ndocumentroot..(.*)@",$fis,$ROOT);
$ROOT=$ROOT[1];
preg_match("@\nip..(.*)@",$fis,$IP);
$IP=$IP[1];
@catalint
catalint / System.php
Created August 14, 2013 13:09
nip framework - Nip_File_System/emptyDir bug
public function emptyDir($dir) {
$this->denyDelete();
$dir = rtrim($dir, "/");
$files = scandir($dir);
array_shift($files);
array_shift($files);
@catalint
catalint / dummy_list.php
Created July 22, 2013 15:46
You can assign to any var the returned variable from the included file
<?php
$list = array();
$list[] = 'a';
$list[] = 'b';
$list[] = 'c';
$list[] = 'd';
return $list;