Skip to content

Instantly share code, notes, and snippets.

View cjus's full-sized avatar
🤓

Carlos Justiniano cjus

🤓
View GitHub Profile
@cjus
cjus / jsonval.sh
Created June 26, 2011 17:42
Extract a JSON value from a BASH script
#!/bin/bash
function jsonval {
temp=`echo $json | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $prop`
echo ${temp##*|}
}
json=`curl -s -X GET http://twitter.com/users/show/$1.json`
prop='profile_image_url'
picurl=`jsonval`
@cjus
cjus / restparse.sh
Created July 18, 2011 19:19
Shell script to query REST server and parse XML node
#!/bin/bash
echo 'XML data monitor. Type CTRL-C to stop'
while :
do
d=`date`
s=`curl -X GET -s http://aserver:4300/server/callqueue/xml | cut -c2-60 | cut -d'>' -f1`
echo $d ' | ' $s
sleep 2
done
@cjus
cjus / geolocation.js
Created July 31, 2011 00:20
WC3 Geolocation
var options = {
enableHighAccuracy: true,
maximumAge: 60000,
timeout: 0
};
if (window.navigator.geolocation) {
navigator.geolocation.getCurrentPosition(successCallback, errorCallback, options);
} else {
alert('Your browser does not natively support geolocation.');
@cjus
cjus / randtest.sh
Created December 23, 2011 00:04
Random numbers in shell scripts
#!/bin/bash
productID[1]=12894ecabe3d01eae4a4dfab8fbfc3a5
productID[2]=4a4f5c9f1347c11080adcd09bd0230e8
productID[3]=4a4f5c9f1347c11080adcd09bd023452
RANDOM=`date '+%s'`
echo ${productID[$[($RANDOM % 2) + 1]]}
echo ${productID[$[($RANDOM % 2) + 1]]}
echo ${productID[$[($RANDOM % 2) + 1]]}
@cjus
cjus / curly-data-extract.py
Created November 27, 2012 00:31
Parse text between curly braces
# src string: Add 2 Arcade Friends within 10 days
p = '{Add} {2} {Arcade Friends} {within} {10} {days}'
[i.split('{')[-1] for i in p.lower().replace(' ','_').split('}') if '{' in i]
@cjus
cjus / .bash_profile
Last active December 27, 2015 15:39
Add uuid alias command to your bash shell
# place line below in .bash_profile
alias uuid='python -c "from uuid import uuid4; print uuid4();"'
@cjus
cjus / sample-nginx.conf
Last active July 12, 2023 14:59
AngularJS Nginx and html5Mode
server {
server_name yoursite.com;
root /usr/share/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
@cjus
cjus / hfind
Created April 9, 2015 18:09
Search in recent shell history
hfind() {
history | grep $1 | grep -v history | grep -v hfind | sed -E 's/^.{7}//' | sort | uniq
}
@cjus
cjus / bash_time_prompt
Last active August 29, 2015 14:24
bash prompt with time display
Add to .bash_profile
export PS1="\n┏━➤ [\D{%T}┊ \u@\h]: \w\n┗━➤ "
New prompt looks like this:
┏━➤ [23:30:23┊ cjus@phoenix]: ~/dev
┗━➤
@cjus
cjus / bkup
Last active August 29, 2015 14:25
Timed stamp, backup command alias for .bash_profile
bkup() {
d=`date +%Y%m%d-%H%M%S`
fname=''$1-$d.tgz
tar czf $fname $1
}