Skip to content

Instantly share code, notes, and snippets.

View dewwwald's full-sized avatar

dewald dewwwald

View GitHub Profile
@dewwwald
dewwwald / index.js
Created March 11, 2020 10:11
Promise.map
// add Promise.map that resolves your promises in a map.
Object.assign(Promise, {
map: function(objectPromiseMap) {
var keys = Object.keys(objectPromiseMap);
return new Promise(function(resolve) {
Promise.all(
keys.map(function(key) {
return objectPromiseMap[key].catch(function(error) {
return Promise.resolve(error);
});
@dewwwald
dewwwald / README.md
Created July 23, 2017 07:06
Building a sass framework

Building a SASS framework

Consideration

  • Could code splitting split my CSS by component, page ets.
  • Why not use bootstrap
  • Mobile first over desktop first / you choose
  • responsive?

Design decitions

  • colors aren't really important as they change on a per project basis
@dewwwald
dewwwald / README.md
Last active July 20, 2017 15:33
Server sider persisting state loop for distributing events

Message Queue and Task Runner

Goal

What I am thinking about is how to set up a message queue that will not only take messages with deadline / dates but also will know how to notify the parent process of the relevant event that has now become executable.

The requirements I have or this task runner is simple. It should store a task name in the database with either a local date or deadline. If a process deadline is close to becoming relevant the task runner should priorotize this task. The task runner need not be a part of the existing application. The date of the task is the date that determines when a task becomes active.

Inspiration

I appreciate what flux has done with their uni-directional flow of data in an application. I believe that the backend can benifit from such an approach.

@dewwwald
dewwwald / _README.md
Last active April 20, 2017 07:31
Node JS Musing - Callbacks / Promise / Async.waterfall

Reason

I created this gist because of a recent question I asked in Z.A. Tech's slack channel.

I said: Hey node people. I have a question about Promise vs Async waterfall. What do you think is more readable? option 1:

    function (done) {
      DataModel.find({ owner: user._id }, function (err, response) {
        done(err, response);
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Mailchimp;

#Last used by editor December 2016

#Setting up node

echo "installing node"
cd ~
curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh
nano nodesource_setup.sh
sudo bash nodesource_setup.sh
@dewwwald
dewwwald / README.md
Last active October 30, 2016 21:41
Help with instagram
@dewwwald
dewwwald / index.php
Last active September 16, 2016 15:30
This is an awesome html aware excerpt.
<?php
/**
* @return string
*/
function html_excerpt($string,$length=150,$ending="&hellip;") {
$opening_regex = '/((?:<[a-zA-Z0-9="\':.,;\-() ]*>)*)(.*)/';
$closing_regex = '/(<\/[a-zA-Z0-9="\':.,;\-() ]*>)/';
$string = trim($string);
$str_len = 0;
@dewwwald
dewwwald / recurse-dirr-delete.php
Created August 4, 2016 11:53
Recurse dirr deletion
private function delete_dir($dirPath)
{
if (! is_dir($dirPath))
{
throw new InvalidArgumentException("$dirPath must be a directory");
}
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/')
{
$dirPath .= '/';
}
function recurse_copy($src,$dst) {
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
recurse_copy($src . '/' . $file,$dst . '/' . $file);
}
else {
copy($src . '/' . $file,$dst . '/' . $file);