Skip to content

Instantly share code, notes, and snippets.

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

Tomás atomsfat

🏠
Working from home
View GitHub Profile
@atomsfat
atomsfat / switchWorkspace.sh
Last active December 19, 2015 00:39
Switch workspace every certain time, util for DIY dashboard
#!/bin/bash
NUMBER_DESkTOP="$(xdotool get_num_desktops)"
CURRENT="0"
echo "Press [CTRL+C] to stop.."
while :
do
xdotool set_desktop $CURRENT
#echo $CURRENT
CURRENT="$(expr $CURRENT + '1')"
if [ "$CURRENT" -gt $NUMBER_DESkTOP ]; then
@atomsfat
atomsfat / backup.sh
Last active December 21, 2015 00:18
Mysql backup shell
#!/bin/bash
fecha=$(date +%Y%m%d_%H%M)
echo "ready to dump database"
mysqldump -u root database --ignore-table=logs > /tmp/dump-$fecha.sql
echo "comprimiendo"
pbzip2 /tmp/dump-$fecha.sql
@atomsfat
atomsfat / copy certificate
Created October 15, 2013 20:29
certficate jenkins
def command = """cat /var/lib/jenkins/.ssh/id_rsa.pub"""// Create the String
def proc = command.execute() // Call *execute* on the string
proc.waitFor() // Wait for the command to finish
// Obtain status and output
println "return code: ${ proc.exitValue()}"
println "stderr: ${proc.err.text}"
println "stdout: ${proc.in.text}" // *out* from the external program is *in* for groovy
@atomsfat
atomsfat / 2roman.groovy
Created December 20, 2013 18:20
cardinal to roman
def cardinalToRoman( int num){
def TreeMap map = [1:"I", 5: "V", 10 : "X", 100 :"C"]
def getLatestKey = {int nu ->
def val = null
for (Map.Entry entry : map.descendingMap().entrySet()) {
def residuo = nu % entry.key;
@atomsfat
atomsfat / Media.groovy
Created January 28, 2014 18:36
Fat grails domain class with custom marshaller
package atoms.fat.media
import grails.converters.JSON
import org.joda.time.DateTime
class Media implements Serializable {
String url
String name
DateTime dateCreated
@atomsfat
atomsfat / BootStrap.groovy
Created January 28, 2014 18:45
BootStrap definition to automatically register custom marshaller
class BootStrap {
def grailsApplication
grailsApplication.getArtefacts("Domain").each{dc->
//here we register custom marshallers declared in domain classes
if(dc.hasProperty("marshaller")){
dc.clazz.marshaller()
}
}
@atomsfat
atomsfat / varnish.vcl
Created August 30, 2016 21:39
Mobile Device Detection via User Agent RegEx Varnish
#Mobile detect https://gist.github.com/dalethedeveloper/1503252
if(req.http.User-Agent ~ ".*(Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune).*")
{
set req.http.X-ua = "mobile";
}else{
set req.http.X-ua = "desktop";
}
sub vcl_hash {
hash_data(req.http.X-ua + ":" + req.url );
#!/bin/bash
CURL_FORMAT="URL: %{url_effective} ReturnCode: %{http_code}, TTFB: %{time_starttransfer}, Total time: %{time_total}, Download Size: %{size_download}"
FILE_URL=$1
TOTAL_URL=$(wc -l < $FILE_URL | xargs)
COUNTER=1
echo "1..$TOTAL_URL"
while read LINE
do
RES=$(curl -L -s -o /dev/null -w "$CURL_FORMAT" $LINE)
@atomsfat
atomsfat / simpleserver.js
Created November 22, 2016 19:01
Simple sever to debug header and url behind proxies
var express = require('express');
var app = express();
app.get('/*', function (req, res) {
console.log(req.originalUrl)
console.log(req.headers)
res.send('Hello World!');
});
app.listen(8090, function () {
@atomsfat
atomsfat / fillform.js
Created April 24, 2017 18:12
fillcustomsform
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://cdn.rawgit.com/Marak/faker.js/master/examples/browser/js/faker.js';
script.onload = function() {
console.log("------>", faker, $("input[name='email']"))
window.randomData = function() {
// console.log("random data");
faker.locale = 'es_MX';