Skip to content

Instantly share code, notes, and snippets.

@Loupax
Loupax / assetPath.js
Last active June 20, 2020 18:28 — forked from cramhead/assetPath.js
A function that returns the path of the provided package asset
var getAssetPath = function getAssetPath(packageName, assetPath) {
assetPath = assetPath || '';
var meteor_root = Npm.require('fs').realpathSync(process.cwd() + '/../');
var assets_folder = meteor_root + '/server/assets/packages/'+packageName.replace(':','_')+'/'+assetPath;
return assets_folder;
};
@Loupax
Loupax / Cache.php
Last active August 29, 2015 14:26
Cache class for PHP
<?php
class Cache {
private $cache = [];
public function functionCall($callable, $params = []){
$hash = serialize([$callable, $params]);
if(!isset($this->cache[$hash])){
$this->cache[$hash] = call_user_func_array($callable, $params);
echo "Function called!\t";
}else{
@Loupax
Loupax / like.php
Last active October 6, 2015 14:27
<?php
/**
* SQL Like operator in PHP.
* Returns TRUE if match else FALSE.
* @param string $pattern
* @param string $subject
* @return bool
*/
function like_match($pattern, $subject)
{
@Loupax
Loupax / Enum.php
Last active October 12, 2015 11:14
<?php
/**
* A class that simulates Enums behaviour
* <code>
* class Season extends Enum{
* const Spring = 0;
* const Summer = 1;
* const Autumn = 2;
* const Winter = 3;
* }
@Loupax
Loupax / AssertGenerator.php
Last active October 29, 2015 09:47
A function that generates assertions against the schema of a specific object
<?php
/**
* Helper function that generates tests for the
* schema and data of a specific object.
*
* NOTE:
* IF THE DATA IN THE OBJECT IS WRONG, THE GENERATED
* TESTS WILL BE WRONG.
* It is still your responsibility to make sure your
@Loupax
Loupax / node-and-npm-in-30-seconds.sh
Created October 26, 2015 08:39 — forked from isaacs/node-and-npm-in-30-seconds.sh
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
/**
* Runs an array of promises one after another instead of in parallel
*
* @param array
* @param callback
*
* @returns {*}
*/
function sequential(array, callback) {
var result = [];
@Loupax
Loupax / die_detector.php
Last active March 23, 2016 15:33
A simple php script that parses a given php file and outputs the location of any die statement that might be forgotten there
#!/usr/local/bin/php
<?php
$expectedTokens = [
'die' => 'T_EXIT',
'exit' => 'T_EXIT',
'var_dump' => 'T_STRING'
];
function extractDieData($fh)
DELETE cu1 FROM db.client_users cu1, db.client_users cu2
WHERE cu1.id > cu2.id
AND cu1.client_user_id = cu2.client_user_id
AND cu1.client_id = cu2.client_id
AND cu1.owner_type = cu2.owner_type
AND cu1.id <> cu2.id;
@Loupax
Loupax / greek-flag.js
Created June 30, 2016 21:24
The Greek flag in a console.log
console.log(
"%c %c %c \n" +
"%c %c %c %c \n" +
"%c %c \n" +
"%c %c %c %c \n" +
"%c %c %c \n" +
"%c \n" +
"%c \n" +
"%c \n" +
"%c \n",