Skip to content

Instantly share code, notes, and snippets.

@exts
exts / Kernel.php
Last active Dec 4, 2017
Symfony 4, Symfony Flex, Vagrant, Failed to remove directory (cache, de~, pools), Windows 10
View Kernel.php
<?php
class Kernel extends BaseKernel
{
use MicroKernelTrait;
const CONFIG_EXTS = '.{php,xml,yaml,yml}';
public function getCacheDir()
{
View decimalToHex.cr
def to_hex(decimal)
decimal_remainder = decimal % 16
hexchars = "0123456789ABCDEF"
div = decimal / 16
if div == 0
hexchars[decimal_remainder].to_s
else
to_hex(div) + hexchars[decimal_remainder].to_s
end
end
View macro-woes.cr
class Test
@stored = [] of Proc(Nil)
def captured(&block)
@stored << block
end
def example
@stored.each do |b|
b.call()
end
View hey-dominos2.js
function say(a) {
cleanUp = function(str) {
return str.replace(/[^a-zA-Z0-9]+/, "");
}
addDashes = function(str) {
return cleanUp(str).split("").join("-");
}
return function(b) {
View heydominos.js
function say(a)
{
splitUp = function(data) {
dataArray = data.split("")
stringArray = [];
for(x = 0; x < dataArray.length; x++) {
if(dataArray[x].match(/[a-zA-Z0-9]/)) {
stringArray[stringArray.length++] = dataArray[x];
}
}
@exts
exts / route-parser.cr
Created Jan 7, 2017
Crystal Lang: Screwing around, trying to figure out a simple way to parse a route w/ named parameters (and optional ones)
View route-parser.cr
#idiotcoder.com
#eatcodegame.com
class RouteParser
@default_regex_replacement = "w+"
getter regex_variables = {} of String => String
getter default_variables = {} of String => String
getter matched_variables = [] of String
@exts
exts / route-container.cr
Last active Jan 5, 2017
Example of how to approach route containers with groups and sub groups in crystal language (inspired by php frameworks such as Slim Framework 3)
View route-container.cr
class Route
def initialize(@route = "")
end
def route
@route
end
end
class RouteContainer
@exts
exts / pass-closure-as-argument.cr
Last active Jan 5, 2017
Pass closure blocks to methods/functions as parameter arguments in crystal language
View pass-closure-as-argument.cr
# idiotcoder.com
def example(&ex)
ex.call()
end
example &-> {
puts "sup"
}
View slimframework3-routes.php
<?php
$app = new \Slim\App();
$app->group('/users/{id:[0-9]+}', function () {
$this->map(['GET', 'DELETE', 'PATCH', 'PUT'], '', function ($request, $response, $args) {
// Find, delete, patch or replace user identified by $args['id']
})->setName('user');
$this->get('/reset-password', function ($request, $response, $args) {
// Route for /users/{id:[0-9]+}/reset-password
// Reset the password for user identified by $args['id']