Skip to content

Instantly share code, notes, and snippets.

View jms's full-sized avatar

Jeronimo Martinez Sanchez jms

View GitHub Profile
@jms
jms / save.py
Created July 18, 2017 06:03
django, save using dict
for attr, value in validated_data.items():
setattr(instance, attr, value)
instance.save()
@jms
jms / check_role.sql
Created July 13, 2017 15:31
validate if a role name exists on postgresql , then execute statement
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_catalago.pg_roles WHERE rolname = 'reader') THEN
CREATE ROLE reader;
END IF;
END
$$;
GRANT SELECT ON tasks TO reader;
--
@jms
jms / ncat-test.sh
Created April 11, 2017 22:29
Test service connection with nmap-ncat
nc --recv-only -v -w 1 65.55.33.135 25
# sample response
# Ncat: Version 6.40 ( http://nmap.org/ncat )
# Ncat: Connected to 65.55.33.135:25.
# 220 COL004-MC6F15.hotmail.com Sending unsolicited commercial or bulk e-mail to Microsoft's computer network is prohibited. Other restrictions are found at http://privacy.microsoft.com/en-us/anti-spam.mspx. Tue, 11 Apr 2017 15:28:03 -0700
# Ncat: Idle timeout expired (1000 ms).
@jms
jms / gist:2b4eefec347c9e125d460e5263c9a146
Created March 21, 2017 00:41
find invalid utf8 characteres with iconv, dd, hexdump
iconv -f GB2312 -t UTF-8 2001.txt -o 2001_u.txt
iconv: illegal input sequence at position 245256667
dd if=2001.txt of=error.txt bs=1 count=10 skip=245256667
hexdump -C error.txt
@jms
jms / gist:76db7918fe3027dc28ba07eaaf34d95c
Created March 8, 2017 22:46
spa - share on social media
# allow social media crawlers to work by redirecting them to a server-rendered static version on the page
RewriteCond %{HTTP_USER_AGENT} (facebookexternalhit/[0-9]|Twitterbot|Pinterest|Google.*snippet)
RewriteRule (.*) https://path_static_page [P]
@jms
jms / test_xpath
Created February 18, 2017 00:38
Google Chrome / Firefox. test on console xpath and css selectors
Google Chrome / Firefox. test on console xpath and css selectors
XPath syntax:
$x("")
CSS syntax:
$$("")
@jms
jms / prevent-doubleclick.js
Created January 11, 2017 16:11
angularjs prevent double click/double submit
$scope.flag = false;
$scope.buttonClicked = function() {
if ($scope.flag) {
return;
}
$scope.flag = true;
Service.doService.then(function(){
//this is the callback for success
$scope.flag = false;
}).error(function(){
@jms
jms / install-tmux
Created January 10, 2017 05:17 — forked from relaxdiego/install-tmux
Install tmux 2.2 on CentOS 7.1
# install deps
yum install gcc kernel-devel make ncurses-devel
# DOWNLOAD SOURCES FOR LIBEVENT AND MAKE AND INSTALL
wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar -xvzf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure --prefix=/usr/local
make
sudo make install
@jms
jms / fix-deps-clojure.sh
Created January 7, 2017 16:00
update certs, fix clojure issue
sudo dpkg-reconfigure ca-certificates;
sudo update-ca-certificates -f
@jms
jms / rm-docker-images.sh
Last active December 31, 2016 00:39
remove docker images
#!/bin/bash
for i in $(docker images | grep none | awk '{print $3}') ; do
docker rmi --force $i
done