Skip to content

Instantly share code, notes, and snippets.

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
@jjmartucci
jjmartucci / copy-contents-bash.md
Created May 7, 2020 16:43
Copy the contents of one direction into another in Bash

cp -R ./src/. ./ e.g.

src/
	file1
	folder/
		file2
		file3

becomes

@jjmartucci
jjmartucci / async-await-map.js
Created May 7, 2020 16:42
Using Async / Await with Array.map()
let characterResponse = await fetch(‘<http://swapi.co/api/people/2/>’)
let characterResponseJson = await characterResponse.json()
let films = await Promise.all(
characterResponseJson.films.map(async filmUrl => {
let filmResponse = await fetch(filmUrl)
return filmResponse.json()
})
)
console.log(films)

Keybase proof

I hereby claim:

  • I am jjmartucci on github.
  • I am jjmartucci (https://keybase.io/jjmartucci) on keybase.
  • I have a public key ASBVaxGHkdJt6wYD26tKvCCmLSO3ZqdlVbOxPJk5MzX-UQo

To claim this, I am signing this object:

@jjmartucci
jjmartucci / get-page-by-slug.php
Created June 21, 2016 13:02 — forked from matheuseduardo/get-page-by-slug.php
get_page_by_slug - wordpress
<?php
/**
* Retrieve a page given its slug.
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $page_slug Page slug
* @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A.
* Default OBJECT.
* @param string|array $post_type Optional. Post type or array of post types. Default 'page'.
sudo apt-get install libicu-dev
cd /tmp
# Install depot_tools first (needed for source checkout)
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=`pwd`/depot_tools:"$PATH"
# Download v8
fetch v8
@jjmartucci
jjmartucci / gist:752d1be204fb241ff48a
Created November 5, 2015 14:31
BEM Nested Selectors for Hover State
.photo-of-the-day {
$root: &;
&--title{
font-size: 16px;
}
&:hover{
#{$root}--title {
text-decoration: underline;
}
}
@jjmartucci
jjmartucci / gist:fce756cdedd6a94b7646
Created February 9, 2015 15:52
Xdebug on Vagrant
zend_extension=xdebug.so
xdebug.remote_enable = 1
xdebug.remote_connect_back = 1
xdebug.idekey = "PHPSTORM"
xdebug.remote_handler = "dbgp"
xdebug.remote_port = 9000
@jjmartucci
jjmartucci / gist:0b9bd6872259440fc129
Created February 2, 2015 20:03
Sort by DateTime
$arr = array(...);
usort($arr, function($a, $b) {
$ad = new DateTime($a['dateTime']);
$bd = new DateTime($b['dateTime']);
if ($ad == $bd) {
return 0;
}
@jjmartucci
jjmartucci / gist:443461bdd069f308e33a
Created January 29, 2015 15:56
jQuery verify a radio button group has been checked
if (!$("input[name='html_elements']:checked").val()) {
alert('Nothing is checked!');
}
else {
alert('One of the radio buttons is checked!');
}