Skip to content

Instantly share code, notes, and snippets.

View astroanu's full-sized avatar
✈️
Working from home

astroanu astroanu

✈️
Working from home
View GitHub Profile
@astroanu
astroanu / gist:d16079463ff01053b7bc4635b8e00d5d
Created April 5, 2024 21:24
Wait for cloudfront invalidation
# creates a new invalidation and waits until it's complete
DISTRIBUTION_ID=xxx
INVALIDATION_ID=$(aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths "/" | jq -r '.Invalidation.Id')
until [[ $(aws cloudfront get-invalidation --id $INVALIDATION_ID --distribution-id $DISTRIBUTION_ID | jq -r '.Invalidation.Status') = "Completed" ]]
do
echo "Waiting for the invalidation to complete"
sleep 3
done
{
"categories":[
{
"from":"0001",
"to":1499,
"category":"Agricultural Services"
},
{
"from":1500,
"to":2999,
@astroanu
astroanu / gist:441634f3b3d7e64fca157d34792288f1
Last active August 8, 2019 10:28
AWS SAM Default starter policy
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject"
],
[program:project]
command=node server/index.js
autostart=true
directory=/home/www/project
autorestart=true
stderr_logfile=/var/log/project.err.log
stdout_logfile=/var/log/project.out.log
server {
server_name domain.xyz;
location / {
proxy_pass http://localhost:3333;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
@astroanu
astroanu / .gitignore
Last active August 29, 2015 14:14
Laravel sample .gitignore
/bootstrap/compiled.php
/vendor
composer.phar
composer.lock
.env.*.php
.env.php
.DS_Store
Thumbs.db
/app/storage/cache
/app/storage/logs
@astroanu
astroanu / gist:15caf94ad60da316df58
Last active August 29, 2015 14:13
generate random id
function getShortenForm($url){
$ignore = array('I','0','O','1');
$alphabet = array_merge(range('A','Z'),array_map(function($i){return (string)$i;},range(0,9)));
$parsing_url = md5($url.'-'.rand().'-'.rand().'-'.microtime(true));
$parsing_url = substr($parsing_url, strlen($parsing_url)/2-1,strlen($parsing_url)).substr($parsing_url, 0,strlen($parsing_url)/2);
$shorten = strtoupper(substr(base_convert($parsing_url,16, 36),0,self::MAX_CHARS));
$cleaned = array_diff($alphabet, $ignore);
$cleaned = array_values($cleaned);
$replaceble = array();
array_walk($ignore,function($val,$key) use (&$replaceble,$cleaned){
@astroanu
astroanu / gearman-server-status.php
Created October 16, 2014 10:36
Gearman server get status
public static function getStatus(){
$status = null;
$handle = fsockopen(gearman_server, gearman_port,$errorNumber,$errorString,30);
if($handle!=null){
fwrite($handle,"status\n");
while (!feof($handle)) {
$line = fgets($handle, 4096);
if( $line==".\n"){
break;
@astroanu
astroanu / underscorejs.object.diff.js
Last active February 22, 2017 21:25
Underscore js object difference
var Objcontains = function(oldO, newO) {
var changed = {};
_.each(newO, function(v, i) {
if (oldO[i] != undefined) {
if (Array.isArray(v)) {
changed[i] = _.difference(v, oldO[i]);
} else if (typeof v == 'object') {
changed[i] = Objcontains(oldO[i], v);
} else {
if (oldO != undefined && (oldO[i] == undefined || oldO[i] != v)) {