Skip to content

Instantly share code, notes, and snippets.

View sendyputra's full-sized avatar
🏠
Working from home

Sendy Putra sendyputra

🏠
Working from home
  • Indonesia
  • 17:42 (UTC +07:00)
  • X @sendypw
View GitHub Profile
@sendyputra
sendyputra / get-npm-package-version
Created September 29, 2023 14:23 — forked from DarrenN/get-npm-package-version
Extract version from package.json (NPM) using bash / shell
# Version key/value should be on his own line
PACKAGE_VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g')
echo $PACKAGE_VERSION
@sendyputra
sendyputra / geo.js
Created October 2, 2019 05:59 — forked from mkhatib/geo.js
A Javascript utility function to generate number of random Geolocations around a center location and in a defined radius.
/**
* Generates number of random geolocation points given a center and a radius.
* @param {Object} center A JS object with lat and lng attributes.
* @param {number} radius Radius in meters.
* @param {number} count Number of points to generate.
* @return {array} Array of Objects with lat and lng attributes.
*/
function generateRandomPoints(center, radius, count) {
var points = [];
for (var i=0; i<count; i++) {
@sendyputra
sendyputra / optimize_images.sh
Created October 17, 2017 08:25 — forked from fosterdill/optimize_images.sh
Find png files that don't have transparency and convert to jpg, also recompress jpg files for the web
#!/bin/sh
echo You should have the project tracked by version control in case something goes wrong.
printf 'Press any key to continue...'
read -r
path=${1:-.}
echo Optimizing images in "$path"
if [ -z "$(command -v jpeg-recompress)" ] || [ -z "$(command -v ladon)" ] || [ -z "$(command -v mogrify)" ]; then
@sendyputra
sendyputra / toAscii.php
Created December 14, 2015 10:02 — forked from chluehr/toAscii.php
PHP clean url slug generator / converter (slug)
<?php
// source: http://cubiq.org/the-perfect-php-clean-url-generator
// author: Matteo Spinelli
// MIT License / http://creativecommons.org/licenses/by-sa/3.0/ (please re-check at source)
setlocale(LC_ALL, 'en_US.UTF8');
function toAscii($str, $replace=array(), $delimiter='-') {
if( !empty($replace) ) {
$str = str_replace((array)$replace, ' ', $str);
}
<?php
/**
* Create a web friendly URL slug from a string.
*
* Although supported, transliteration is discouraged because
* 1) most web browsers support UTF-8 characters in URLs
* 2) transliteration causes a loss of information
*
* @author Sean Murphy <sean@iamseanmurphy.com>
* @copyright Copyright 2012 Sean Murphy. All rights reserved.
#! /bin/sh
# Usage 1:
# optimize-images.sh /images/dir
#
# Usage 2:
# cd /images/dir
# optimize-images.sh
EXTENSIONS="jpe?g"
#!/opt/local/bin/php
<?php
/*
1) replace the shebang (first line) with the path to your php binary
(probably something like /usr/bin/php)
2) move the file to /usr/local/bin/datauri.php
(this should be in your PATH)
3) chmod ugo+rx /usr/local/bin/datauri.php
(make the script executable for everyone)