<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>xploit29</title>
	<atom:link href="https://xploit29.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://xploit29.com</link>
	<description>Cool code tips.</description>
	<lastBuildDate>Thu, 15 Nov 2018 22:11:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
<site xmlns="com-wordpress:feed-additions:1">3997858</site>	<item>
		<title>Multiple environments on NewRelic</title>
		<link>https://xploit29.com/2018/11/15/multiple-environments-on-newrelic/</link>
					<comments>https://xploit29.com/2018/11/15/multiple-environments-on-newrelic/#respond</comments>
		
		<dc:creator><![CDATA[Irving Kcam]]></dc:creator>
		<pubDate>Thu, 15 Nov 2018 22:10:15 +0000</pubDate>
				<category><![CDATA[SysAdmin]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[NewRelic]]></category>
		<guid isPermaLink="false">http://xploit29.com/?p=91</guid>

					<description><![CDATA[<p>About New Relic it&#8217;s a powerful tool that handles application monitoring. Configuration It is a good practice setting environment variables to define and configure our NewRelic parameters. newrelic.ini&#160;example: As you can see I have all the common settings under the [newrelic]&#160;tag and by default I set monitor_mode = false&#160;and developer_mode = true. 2 environments have been [&#8230;]</p>
The post <a href="https://xploit29.com/2018/11/15/multiple-environments-on-newrelic/">Multiple environments on NewRelic</a> first appeared on <a href="https://xploit29.com">xploit29</a>.]]></description>
										<content:encoded><![CDATA[<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://i2.wp.com/xploit29.com/wp-content/uploads/2018/11/og-newrelic-logo.png?resize=750%2C250&amp;ssl=1" alt="" class="wp-image-99"/></figure></div>



<h3 class="wp-block-heading">About</h3>



<p>New Relic it&#8217;s a powerful tool that handles application monitoring.</p>



<span id="more-91"></span>



<h3 class="wp-block-heading">Configuration</h3>



<p>It is a good practice setting environment variables to define and configure our NewRelic parameters.</p>



<p><code>newrelic.ini</code>&nbsp;example:</p>



<pre class="wp-block-code"><code>[newrelic]

# You must specify the license key associated with your New
# Relic account. This key binds the Python Agent's data to your
# account in the New Relic service.
license_key = YOUR_LICENSE_KEY

# The application name. Set this to be the name of your
# application as you would like it to show up in New Relic UI.
# The UI will then auto-map instances of your application into a
# entry on your home dashboard page.
app_name = YOU_APP_NAME

# When "true", the agent collects performance data about your
# application and reports this data to the New Relic UI at
# newrelic.com. This global switch is normally overridden for
# each environment below.
monitor_mode = false
developer_mode = true

# Sets the name of a file to log agent messages to. Useful for
# debugging any issues with the agent. This is not set by
# default as it is not known in advance what user your web
# application processes will run as and where they have
# permission to write to. Whatever you set this to you must
# ensure that the permissions for the containing directory and
# the file itself are correct, and that the user that your web
# application runs as can write to the file. If not able to
# write out a log file, it is also possible to say "stderr" and
# output to standard error output. This would normally result in
# output appearing in your web server log.
log_file = stderr

# Sets the level of detail of messages sent to the log file, if
# a log file location has been provided. Possible values, in
# increasing order of detail, are: "critical", "error", "warning",
# "info" and "debug". When reporting any agent issues to New
# Relic technical support, the most useful setting for the
# support engineers is "debug". However, this can generate a lot
# of information very quickly, so it is best not to keep the
# agent at this level for longer than it takes to reproduce the
# problem you are experiencing.
log_level = info

# The Python Agent communicates with the New Relic service using
# SSL by default. Note that this does result in an increase in
# CPU overhead, over and above what would occur for a non SSL
# connection, to perform the encryption involved in the SSL
# communication. This work is though done in a distinct thread
# to those handling your web requests, so it should not impact
# response times. You can if you wish revert to using a non SSL
# connection, but this will result in information being sent
# over a plain socket connection and will not be as secure.
ssl = true

# High Security Mode enforces certain security settings, and
# prevents them from being overridden, so that no sensitive data
# is sent to New Relic. Enabling High Security Mode means that
# SSL is turned on, request parameters are not collected, and SQL
# can not be sent to New Relic in its raw form. To activate High
# Security Mode, it must be set to 'true' in this local .ini
# configuration file AND be set to 'true' in the server-side
# configuration in the New Relic user interface. For details, see
# https://docs.newrelic.com/docs/subscriptions/high-security
high_security = false

# The Python Agent will attempt to connect directly to the New
# Relic service. If there is an intermediate firewall between
# your host and the New Relic service that requires you to use a
# HTTP proxy, then you should set both the "proxy_host" and
# "proxy_port" settings to the required values for the HTTP
# proxy. The "proxy_user" and "proxy_pass" settings should
# additionally be set if proxy authentication is implemented by
# the HTTP proxy. The "proxy_scheme" setting dictates what
# protocol scheme is used in talking to the HTTP proxy. This
# would normally always be set as "http" which will result in the
# agent then using a SSL tunnel through the HTTP proxy for end to
# end encryption.
# proxy_scheme = http
# proxy_host = hostname
# proxy_port = 8080
# proxy_user =
# proxy_pass =

# Capturing request parameters is off by default. To enable the
# capturing of request parameters, first ensure that the setting
# "attributes.enabled" is set to "true" (the default value), and
# then add "request.parameters.*" to the "attributes.include"
# setting. For details about attributes configuration, please
# consult the documentation.
attributes.include = request.parameters.*

# ---------------------------------------------------------------------------

#
# The application environments. These are specific settings which
# override the common environment settings. The settings related to a
# specific environment will be used when the environment argument to the
# newrelic.agent.initialize() function has been defined to be either
# "development", "pytest", "preprod" or "production".
#

[newrelic:staging]
app_name = YOU_APP_NAME (Staging)
monitor_mode = true
developer_mode = false

[newrelic:production]
monitor_mode = true
developer_mode = false

# ---------------------------------------------------------------------------
</code></pre>



<p>As you can see I have all the common settings under the <code>[newrelic]</code>&nbsp;tag and by default I set <code>monitor_mode = false</code>&nbsp;and <code>developer_mode = true</code>.</p>



<p>2 environments have been declared on that file, <code>production</code> and <code>staging</code>, so if I wanna use <code>production</code> I just need to declare <code>NEW_RELIC_ENVIRONMENT</code> and I&#8217;m good to go.</p>



<pre class="wp-block-code"><code>NEW_RELIC_ENVIRONMENT=production
NEW_RELIC_CONFIG_FILE=conf/newrelic.ini

export NEW_RELIC_ENVIRONMENT
export NEW_RELIC_CONFIG_FILE</code></pre>



<p>Finally run New Relic as documented on their manuals.</p>



<pre class="wp-block-code"><code># Example: Python agent
newrelic-admin run-program YOUR_COMMAND_OPTIONS</code></pre>



<p></p>The post <a href="https://xploit29.com/2018/11/15/multiple-environments-on-newrelic/">Multiple environments on NewRelic</a> first appeared on <a href="https://xploit29.com">xploit29</a>.]]></content:encoded>
					
					<wfw:commentRss>https://xploit29.com/2018/11/15/multiple-environments-on-newrelic/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">91</post-id>	</item>
		<item>
		<title>Setup streaming replication with PostgreSQL 10</title>
		<link>https://xploit29.com/2018/11/04/setup-streaming-replication-with-postgresql-10/</link>
					<comments>https://xploit29.com/2018/11/04/setup-streaming-replication-with-postgresql-10/#comments</comments>
		
		<dc:creator><![CDATA[Irving Kcam]]></dc:creator>
		<pubDate>Sun, 04 Nov 2018 18:25:39 +0000</pubDate>
				<category><![CDATA[SysAdmin]]></category>
		<category><![CDATA[DevOPS]]></category>
		<category><![CDATA[Postgres]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Replication]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Servers]]></category>
		<guid isPermaLink="false">http://www.xploit29.com/?p=82</guid>

					<description><![CDATA[<p>Requirements Ubuntu 16.04 or Ubuntu 18.04 PostgreSQL 10 2 servers (a master and a slave) In case you don&#8217;t know how to install PostgreSQL you can follow this tutorial from DigitalOcean. Setup It&#8217;s highly recommended to use two servers that can communicate via on a private interface. Master server: 192.168.123.10 Slave server: 192.168.123.11 Master server [&#8230;]</p>
The post <a href="https://xploit29.com/2018/11/04/setup-streaming-replication-with-postgresql-10/">Setup streaming replication with PostgreSQL 10</a> first appeared on <a href="https://xploit29.com">xploit29</a>.]]></description>
										<content:encoded><![CDATA[<div class="wp-block-image"><figure class="aligncenter"><img data-recalc-dims="1" fetchpriority="high" decoding="async" width="600" height="219" src="https://i0.wp.com/xploit29.com/wp-content/uploads/2018/11/slonik_with_black_text_and_tagline.gif?resize=600%2C219&#038;ssl=1" alt="" class="wp-image-78"/></figure></div>



<h3 class="wp-block-heading">Requirements</h3>



<ul class="wp-block-list"><li>Ubuntu 16.04 or Ubuntu 18.04</li><li>PostgreSQL 10</li><li>2 servers (a master and a slave)</li></ul>



<p>In case you don&#8217;t know how to install PostgreSQL you can follow this <a href="https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-18-04" target="_blank" rel="noreferrer noopener">tutorial from DigitalOcean</a>.</p>



<span id="more-82"></span>



<h3 class="wp-block-heading">Setup</h3>



<p>It&#8217;s highly recommended to use two servers that can communicate via on a private interface.</p>



<ul class="wp-block-list"><li><strong>Master server</strong>: <code>192.168.123.10</code></li><li><strong>Slave server</strong>: <code>192.168.123.11</code></li></ul>



<h3 class="wp-block-heading">Master server configuration</h3>



<p>Create a role dedicated to the replication, you can freely choose the username and password that you like.</p>



<pre class="wp-block-code"><code>su - postgres psql</code></pre>



<pre class="wp-block-code"><code>CREATE ROLE replication WITH ENCRYPTED PASSWORD 'password';
ALTER ROLE replication WITH REPLICATION;</code></pre>



<p>Modify the <code>/etc/postgresql/10/main/postgresql.conf</code></p>



<pre class="wp-block-code"><code>listen_addresses = 'localhost, 127.0.0.1, 192.168.123.10'
wal_level = replica
max_wal_senders = 3 # max number of walsender processes
wal_keep_segments = 64 # in logfile segments, 16MB each; 0 disables</code></pre>



<p>Modify the <code>/etc/postgresql/10/main/pg_hba.conf</code>&nbsp;file to allow access from the <strong>Slave server</strong>.</p>



<pre class="wp-block-code"><code>host    replication    replicate    192.168.123.11/24    md5</code></pre>



<p>Restart PostgreSQL.</p>



<pre class="wp-block-code"><code>service postgresql restart</code></pre>



<h3 class="wp-block-heading">Slave server configuration</h3>



<p>Modify the <code>/etc/postgresql/10/main/postgresql.conf</code></p>



<pre class="wp-block-code"><code>listen_addresses = 'localhost, 127.0.0.1, 192.168.123.11'
wal_level = replica
max_wal_senders = 3 # max number of walsender processes
wal_keep_segments = 64 # in logfile segments, 16MB each; 0 disables
hot_standby = on</code></pre>



<p>Modify the <code>/etc/postgresql/10/main/pg_hba.conf</code>&nbsp;file to allow access from the <strong>Slave server</strong>.</p>



<pre class="wp-block-code"><code>host    replication    replicate    192.168.123.10/24    md5</code></pre>



<p>Stop PostgreSQL</p>



<pre class="wp-block-code"><code>service postgresql stop</code></pre>



<p>Delete all the files inside the <strong>PGDATA</strong> folder. Keep in mind that this folder may change, you may wanna check your <code>postgresql.conf</code>&nbsp;file and lookup for the <code>data_directory</code>&nbsp;setting.</p>



<pre class="wp-block-code"><code>rm -rf /var/lib/postgresql/10/main/*</code></pre>



<p>Now we will copy all the data from the master with the <code>pg_basebackup</code> command. You must run this command as the postgresql user.</p>



<pre class="wp-block-code"><code>su - postgresql
pg_basebackup -h 192.168.123.10 -D /var/lib/postgresql/10/main/ -P -U replicate --wal-method=stream</code></pre>



<p>You can press <code>CTRL + D</code>&nbsp;to leave the <code>postgresql</code>&nbsp;user and create a file named <code>recovery.conf</code>&nbsp;on your <code>PGDATA</code> folder</p>



<pre class="wp-block-code"><code>nano /var/lib/postgresql/10/main/recovery.conf</code></pre>



<pre class="wp-block-code"><code>standby_mode          = 'on'
primary_conninfo      = 'host=192.168.123.10 port=5432 user=replicate password=password'
trigger_file = '/tmp/MasterNow'
#restore_command = 'cp /home/postgresql_wal/%f "%p"'</code></pre>



<p>Here is an explanation for each line:</p>



<ul class="wp-block-list"><li><code>standby_mode=on</code>: specifies that the server must start as a standby server</li><li><code>primary_conninfo</code>: the parameters to use to connect to the master</li><li><code>trigger_file</code>: if this file exists, the server will stop the replication and act as a master</li><li><code>restore_command</code>: this command is only needed if you have used the archive_command on the master</li></ul>



<p>Start PostgreSQL.</p>



<pre class="wp-block-code"><code>service postgresql start</code></pre>



<h3 class="wp-block-heading">Finally</h3>



<p>You can see the replicate user on the <strong>Master server</strong>.</p>



<pre class="wp-block-code"><code>su - postgresql psql</code></pre>



<pre class="wp-block-code"><code>SELECT * FROM pg_stat_activity WHERE usename = 'replicate';</code></pre>



<p>Your database is ready.</p>The post <a href="https://xploit29.com/2018/11/04/setup-streaming-replication-with-postgresql-10/">Setup streaming replication with PostgreSQL 10</a> first appeared on <a href="https://xploit29.com">xploit29</a>.]]></content:encoded>
					
					<wfw:commentRss>https://xploit29.com/2018/11/04/setup-streaming-replication-with-postgresql-10/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">82</post-id>	</item>
		<item>
		<title>Seguridad: Las URLS en Facebook y los anuncios</title>
		<link>https://xploit29.com/2016/10/16/seguridad-las-urls-en-facebook-y-los-anuncios/</link>
					<comments>https://xploit29.com/2016/10/16/seguridad-las-urls-en-facebook-y-los-anuncios/#respond</comments>
		
		<dc:creator><![CDATA[Irving Kcam]]></dc:creator>
		<pubDate>Sun, 16 Oct 2016 17:23:19 +0000</pubDate>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Problema]]></category>
		<category><![CDATA[Seguridad]]></category>
		<guid isPermaLink="false">http://www.xploit29.com/?p=40</guid>

					<description><![CDATA[<p>El día de hoy en Facebook me topé con una publicidad engañosa de unos de los bancos más grandes del mundo. A lo procedí a ingresar a la página para reportarla como falsa tras comprobar que realmente era falsa y observé algo muy extraño, que la URL era: https://www.facebook.com/BBVAContinentaI/ lo que visualmente se ve de la siguiente [&#8230;]</p>
The post <a href="https://xploit29.com/2016/10/16/seguridad-las-urls-en-facebook-y-los-anuncios/">Seguridad: Las URLS en Facebook y los anuncios</a> first appeared on <a href="https://xploit29.com">xploit29</a>.]]></description>
										<content:encoded><![CDATA[<p>El día de hoy en Facebook me topé con una publicidad engañosa de unos de los bancos más grandes del mundo. A lo procedí a ingresar a la página para reportarla como falsa tras comprobar que realmente era falsa y observé algo muy extraño, que la URL era: <del>https://www.facebook.com/BBVAContinentaI/</del> lo que visualmente se ve de la siguiente manera:</p>
<p><div id="attachment_41" style="width: 672px" class="wp-caption aligncenter"><img data-recalc-dims="1" decoding="async" aria-describedby="caption-attachment-41" class="wp-image-41 size-full" src="https://i0.wp.com/www.xploit29.com/wp-content/uploads/2016/10/Captura-de-pantalla-2016-10-16-a-las-12.01.06.png?resize=600%2C63" alt="captura-de-pantalla-2016-10-16-a-las-12-01-06" width="600" height="63" srcset="https://i0.wp.com/xploit29.com/wp-content/uploads/2016/10/Captura-de-pantalla-2016-10-16-a-las-12.01.06.png?w=662&amp;ssl=1 662w, https://i0.wp.com/xploit29.com/wp-content/uploads/2016/10/Captura-de-pantalla-2016-10-16-a-las-12.01.06.png?resize=300%2C32&amp;ssl=1 300w, https://i0.wp.com/xploit29.com/wp-content/uploads/2016/10/Captura-de-pantalla-2016-10-16-a-las-12.01.06.png?resize=660%2C70&amp;ssl=1 660w" sizes="(max-width: 600px) 100vw, 600px" /><p id="caption-attachment-41" class="wp-caption-text">Captura de la URL de la página falsa en Facebook.</p></div></p>
<p>Ahora veamos como se ve la URL de la página oficial es: https://www.facebook.com/BBVAContinental/.</p>
<p><div id="attachment_42" style="width: 666px" class="wp-caption aligncenter"><img data-recalc-dims="1" decoding="async" aria-describedby="caption-attachment-42" class="wp-image-42 size-full" src="https://i0.wp.com/www.xploit29.com/wp-content/uploads/2016/10/Captura-de-pantalla-2016-10-16-a-las-12.03.42.png?resize=600%2C66" alt="captura-de-pantalla-2016-10-16-a-las-12-03-42" width="600" height="66" srcset="https://i0.wp.com/xploit29.com/wp-content/uploads/2016/10/Captura-de-pantalla-2016-10-16-a-las-12.03.42.png?w=656&amp;ssl=1 656w, https://i0.wp.com/xploit29.com/wp-content/uploads/2016/10/Captura-de-pantalla-2016-10-16-a-las-12.03.42.png?resize=300%2C33&amp;ssl=1 300w" sizes="(max-width: 600px) 100vw, 600px" /><p id="caption-attachment-42" class="wp-caption-text">Captura de la URL de la página oficial en Facebook.</p></div></p>
<h3>¿Cuál es la diferencia?</h3>
<p>La igualdad gráfica entre la &#8220;I&#8221; (i &#8211; vocal) mayúscula y la &#8220;l&#8221; (L &#8211; ele) minúscula.</p>
<h3>¿Debería Facebook normalizar la URL de las páginas a minúsculas?</h3>
<p>No, porque más importante que el cambio de mayúsculas a minúsculas son los <strong>filtros para empresas que anuncian en Facebook</strong>. Diariamente cientos <strong>páginas de Facebook fraudulentas que poseen el mismo nombre de las páginas a las cuales replican</strong> publican anuncios con un fin maligno.</p>
<p>Mejor control:</p>
<ul>
<li><strong>Páginas que poseen el mismo nombre</strong> que páginas verificadas no deberían ser autorizados a publicar anuncio alguno.</li>
<li>No es posible reportar anuncios como posible<strong> suplantación o fraude</strong>.</li>
</ul>
<p><div id="attachment_43" style="width: 656px" class="wp-caption aligncenter"><img data-recalc-dims="1" loading="lazy" decoding="async" aria-describedby="caption-attachment-43" class="wp-image-43 size-full" src="https://i0.wp.com/www.xploit29.com/wp-content/uploads/2016/10/Captura-de-pantalla-2016-10-16-a-las-12.19.18.png?resize=600%2C476" alt="Opciones actuales para el reporte de anuncios." width="600" height="476" srcset="https://i0.wp.com/xploit29.com/wp-content/uploads/2016/10/Captura-de-pantalla-2016-10-16-a-las-12.19.18.png?w=646&amp;ssl=1 646w, https://i0.wp.com/xploit29.com/wp-content/uploads/2016/10/Captura-de-pantalla-2016-10-16-a-las-12.19.18.png?resize=300%2C238&amp;ssl=1 300w" sizes="auto, (max-width: 600px) 100vw, 600px" /><p id="caption-attachment-43" class="wp-caption-text">Opciones actuales para el reporte de anuncios.</p></div></p>
<ul>
<li>El reporte o denuncia de posibles fan pages falsos no permite que la página sea revisada por el personal de Facebook. Este punto es sumamente importante pues actualmente el proceso de reporte es de dos pasos y <strong>no permite reportarlo al personal de Facebook</strong>.</li>
</ul>The post <a href="https://xploit29.com/2016/10/16/seguridad-las-urls-en-facebook-y-los-anuncios/">Seguridad: Las URLS en Facebook y los anuncios</a> first appeared on <a href="https://xploit29.com">xploit29</a>.]]></content:encoded>
					
					<wfw:commentRss>https://xploit29.com/2016/10/16/seguridad-las-urls-en-facebook-y-los-anuncios/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">40</post-id>	</item>
		<item>
		<title>Weight distribution matters.</title>
		<link>https://xploit29.com/2016/10/06/weight-distribution-matters/</link>
					<comments>https://xploit29.com/2016/10/06/weight-distribution-matters/#respond</comments>
		
		<dc:creator><![CDATA[Irving Kcam]]></dc:creator>
		<pubDate>Thu, 06 Oct 2016 15:39:42 +0000</pubDate>
				<category><![CDATA[Offtopic]]></category>
		<category><![CDATA[Trailers]]></category>
		<guid isPermaLink="false">http://www.xploit29.com/?p=33</guid>

					<description><![CDATA[<p>Next time, you&#8217;ll know it.</p>
The post <a href="https://xploit29.com/2016/10/06/weight-distribution-matters/">Weight distribution matters.</a> first appeared on <a href="https://xploit29.com">xploit29</a>.]]></description>
										<content:encoded><![CDATA[<p><iframe loading="lazy" src="https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2FArchiDesiign%2Fvideos%2F988802944608294%2F&#038;show_text=0&#038;width=560" width="100%" height="420px" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true" allowFullScreen="true"></iframe></p>
<p>Next time, you&#8217;ll know it.</p>The post <a href="https://xploit29.com/2016/10/06/weight-distribution-matters/">Weight distribution matters.</a> first appeared on <a href="https://xploit29.com">xploit29</a>.]]></content:encoded>
					
					<wfw:commentRss>https://xploit29.com/2016/10/06/weight-distribution-matters/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">33</post-id>	</item>
		<item>
		<title>Django Rest Framework auto assign current user on creation</title>
		<link>https://xploit29.com/2016/09/15/django-rest-framework-auto-assign-current-user-on-creation/</link>
					<comments>https://xploit29.com/2016/09/15/django-rest-framework-auto-assign-current-user-on-creation/#respond</comments>
		
		<dc:creator><![CDATA[Irving Kcam]]></dc:creator>
		<pubDate>Fri, 16 Sep 2016 05:17:15 +0000</pubDate>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Django Rest Framework]]></category>
		<category><![CDATA[DRF]]></category>
		<guid isPermaLink="false">http://www.xploit29.com/?p=30</guid>

					<description><![CDATA[<p>If you use the ModelViewSet provided by Django Rest Framework you overwrite the perform_create method on the ModelViewSet to auto set the current user to the model before saving. As usual my recommendation is to create &#8220;Mixin&#8221; like this one: If you think that there is a better way, let us know in the comments bellow.</p>
The post <a href="https://xploit29.com/2016/09/15/django-rest-framework-auto-assign-current-user-on-creation/">Django Rest Framework auto assign current user on creation</a> first appeared on <a href="https://xploit29.com">xploit29</a>.]]></description>
										<content:encoded><![CDATA[<p>If you use the <code>ModelViewSet</code> provided by <a href="http://www.django-rest-framework.org/api-guide/viewsets/">Django Rest Framework</a> you overwrite the <code>perform_create</code> method on the <code>ModelViewSet</code> to auto set the current user to the model before saving.</p>
<pre class="brush: python; title: ; notranslate">
class PostViewSet(viewsets.ModelViewSet):
  queryset         = Post.objects.all()
  serializer_class = serializers.PostSerializer

  def perform_create(self, serializer):
    kwargs = {
      'user': self.request.user # Change 'user' to you model user field.
    }

    serializer.save(**kwargs)
</pre>
<p>As usual my recommendation is to create &#8220;Mixin&#8221; like this one:</p>
<pre class="brush: python; title: ; notranslate">
class UserCreateMixin(object):
  &quot;&quot;&quot;
  By default the user field is &quot;user&quot; you can change it
  to your model &quot;user&quot; field.

  Usage:
  class PostViewSet(UserCreateMixin, viewsets.ModelViewSet):
    # ViewsSet required info...
    user_field = 'creator'
  &quot;&quot;&quot;
  user_field = 'user'

  def get_user_field(self):
    &quot;&quot;&quot;
    You can dynamically change the user field
    &quot;&quot;&quot;
    return self.user_field

  def perform_create(self, serializer):
    kwargs = {
      self.get_user_field(): self.request.user
    }

    serializer.save(**kwargs)
</pre>
<p>If you think that there is a better way, let us know in the comments bellow.</p>The post <a href="https://xploit29.com/2016/09/15/django-rest-framework-auto-assign-current-user-on-creation/">Django Rest Framework auto assign current user on creation</a> first appeared on <a href="https://xploit29.com">xploit29</a>.]]></content:encoded>
					
					<wfw:commentRss>https://xploit29.com/2016/09/15/django-rest-framework-auto-assign-current-user-on-creation/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">30</post-id>	</item>
		<item>
		<title>Upload files to Django Rest Framework using AngularJS</title>
		<link>https://xploit29.com/2016/09/13/upload-files-to-django-rest-framework-using-angularjs/</link>
					<comments>https://xploit29.com/2016/09/13/upload-files-to-django-rest-framework-using-angularjs/#comments</comments>
		
		<dc:creator><![CDATA[Irving Kcam]]></dc:creator>
		<pubDate>Tue, 13 Sep 2016 13:55:46 +0000</pubDate>
				<category><![CDATA[AngularJS]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">http://www.xploit29.com/?p=20</guid>

					<description><![CDATA[<p>Encoding the image to &#8220;base64&#8221;, send it to our DRF endpoint and on our DRF serializers change the ImageField to Base64ImageField was the implementation I used: On the client side, on my angular app: angular.controller('ImageUploadFormCtrl', function($scope, Photo){ $scope.submitForm = function(isValid){ if(isValid){ f = new FileReader(); // or $window.FileReader() f.onload = function () { $scope.formData.image = f.result; [&#8230;]</p>
The post <a href="https://xploit29.com/2016/09/13/upload-files-to-django-rest-framework-using-angularjs/">Upload files to Django Rest Framework using AngularJS</a> first appeared on <a href="https://xploit29.com">xploit29</a>.]]></description>
										<content:encoded><![CDATA[<p>Encoding the image to &#8220;base64&#8221;, send it to our DRF endpoint and on our DRF serializers change the ImageField to Base64ImageField was the implementation I used:</p>
<p>On the client side, on my angular app:</p>
<pre class="brush: jscript; title: ; notranslate">
angular.controller('ImageUploadFormCtrl', function($scope, Photo){
  $scope.submitForm = function(isValid){
    if(isValid){
      f = new FileReader(); // or $window.FileReader()
      
      f.onload = function () {
        $scope.formData.image = f.result; // This is a base64 string

        Photo.save({}, $scope.formData).$promise.then(function(data){
          // 200 Response
          alert('Client image successfully updated.');
        }, function(error){
          // 400 Response
          console.log('Error', error);
          alert('An error has ocurred.');
        })
      };      
      
      // Read the file selected on the field with ID &quot;image-field&quot;
      f.readAsDataURL(document.getElementById('image-field').files&#x5B;0]);
    }
  }
});
</pre>
<p>On the server side on my Django app, specifically on the <code>serializers.py</code> file:</p>
<pre class="brush: python; title: ; notranslate">
import base64, uuid
from django.core.files.base import ContentFile

class Base64ImageField(serializers.ImageField):
  def to_internal_value(self, data):
    if isinstance(data, basestring) and data.startswith('data:'): # You can change &quot;data:&quot; to &quot;data/image:&quot;
      format, imgstr = data.split(';base64,')
      ext  = format.split('/')&#x5B;-1]
      id   = uuid.uuid4()
      data = ContentFile(base64.b64decode(imgstr), name=id.urn&#x5B;9:])

    return super(Base64ImageField, self).to_internal_value(data)

class PhotoSerializer(serializers.ModelSerializer):
  image = Base64ImageField(allow_empty_file=False)
  
  class Meta:
    fields           = ('id', 'image')
    model            = Photo
    read_only_fields = ('id', )
</pre>
<p>I found out that this is the cleaner way to do this. If you have another alternative, please share it.</p>The post <a href="https://xploit29.com/2016/09/13/upload-files-to-django-rest-framework-using-angularjs/">Upload files to Django Rest Framework using AngularJS</a> first appeared on <a href="https://xploit29.com">xploit29</a>.]]></content:encoded>
					
					<wfw:commentRss>https://xploit29.com/2016/09/13/upload-files-to-django-rest-framework-using-angularjs/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">20</post-id>	</item>
		<item>
		<title>Require activated virtualenv on PIP</title>
		<link>https://xploit29.com/2016/09/09/require-activated-virtualenv-on-pip/</link>
					<comments>https://xploit29.com/2016/09/09/require-activated-virtualenv-on-pip/#respond</comments>
		
		<dc:creator><![CDATA[Irving Kcam]]></dc:creator>
		<pubDate>Fri, 09 Sep 2016 15:12:09 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[PIP]]></category>
		<category><![CDATA[Sublime Text]]></category>
		<guid isPermaLink="false">http://www.xploit29.com/?p=12</guid>

					<description><![CDATA[<p>I highly recommended to separate your working environments so every project has their own set of packages. To do this just edit the ~/.bash_profile file. export PIP_REQUIRE_VIRTUALENV=true # define a &#34;global pip&#34; function to use outside virtualenv: gpip(){ PIP_REQUIRE_VIRTUALENV=&#34;&#34; pip &#34;$@&#34; } After that, reload the source file with this command source ~/.bash_profile.</p>
The post <a href="https://xploit29.com/2016/09/09/require-activated-virtualenv-on-pip/">Require activated virtualenv on PIP</a> first appeared on <a href="https://xploit29.com">xploit29</a>.]]></description>
										<content:encoded><![CDATA[<p>I highly recommended to separate your working environments so every project has their own set of packages. To do this just edit the <code>~/.bash_profile</code> file.</p>
<pre class="brush: bash; title: ; notranslate">
export PIP_REQUIRE_VIRTUALENV=true
# define a &quot;global pip&quot; function to use outside virtualenv:
gpip(){
    PIP_REQUIRE_VIRTUALENV=&quot;&quot; pip &quot;$@&quot;
}
</pre>
<p>After that, reload the source file with this command <code>source ~/.bash_profile</code>.</p>The post <a href="https://xploit29.com/2016/09/09/require-activated-virtualenv-on-pip/">Require activated virtualenv on PIP</a> first appeared on <a href="https://xploit29.com">xploit29</a>.]]></content:encoded>
					
					<wfw:commentRss>https://xploit29.com/2016/09/09/require-activated-virtualenv-on-pip/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">12</post-id>	</item>
		<item>
		<title>WordPress HTTPS Redirection</title>
		<link>https://xploit29.com/2016/09/08/wordpress-https-redirection/</link>
					<comments>https://xploit29.com/2016/09/08/wordpress-https-redirection/#respond</comments>
		
		<dc:creator><![CDATA[Irving Kcam]]></dc:creator>
		<pubDate>Thu, 08 Sep 2016 22:28:27 +0000</pubDate>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[SSL]]></category>
		<category><![CDATA[Tip]]></category>
		<guid isPermaLink="false">http://xploit29.com/?p=4</guid>

					<description><![CDATA[<p>You don&#8217;t need to install any kind plugin to achieve this. Just go to &#8220;Settings&#8221; &#62; &#8220;General&#8221; and them update your &#8220;WordPress Address&#8221; and the &#8220;Site Address&#8220;. Change the &#8220;http&#8221; to &#8220;https&#8221; as the following image. Really, that&#8217;s it! and you are good to go.</p>
The post <a href="https://xploit29.com/2016/09/08/wordpress-https-redirection/">WordPress HTTPS Redirection</a> first appeared on <a href="https://xploit29.com">xploit29</a>.]]></description>
										<content:encoded><![CDATA[<p>You don&#8217;t need to install any kind plugin to achieve this. Just go to &#8220;<strong>Settings</strong>&#8221; &gt; &#8220;<strong>General</strong>&#8221; and them update your &#8220;<strong>WordPress Address</strong>&#8221; and the &#8220;<strong>Site Address</strong>&#8220;. Change the &#8220;<strong>http</strong>&#8221; to &#8220;<strong>https</strong>&#8221; as the following image.</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" class="aligncenter wp-image-5 size-large" src="https://i0.wp.com/xploit29.com/wp-content/uploads/2016/09/Captura-de-pantalla-2016-09-08-a-las-17.26.30.png?resize=600%2C114&#038;ssl=1" alt="captura-de-pantalla-2016-09-08-a-las-17-26-30" width="600" height="114" srcset="https://i0.wp.com/xploit29.com/wp-content/uploads/2016/09/Captura-de-pantalla-2016-09-08-a-las-17.26.30.png?resize=1024%2C195&amp;ssl=1 1024w, https://i0.wp.com/xploit29.com/wp-content/uploads/2016/09/Captura-de-pantalla-2016-09-08-a-las-17.26.30.png?resize=300%2C57&amp;ssl=1 300w, https://i0.wp.com/xploit29.com/wp-content/uploads/2016/09/Captura-de-pantalla-2016-09-08-a-las-17.26.30.png?resize=768%2C147&amp;ssl=1 768w, https://i0.wp.com/xploit29.com/wp-content/uploads/2016/09/Captura-de-pantalla-2016-09-08-a-las-17.26.30.png?w=1174&amp;ssl=1 1174w" sizes="auto, (max-width: 600px) 100vw, 600px" /></p>
<p>Really, that&#8217;s it! and you are good to go.</p>The post <a href="https://xploit29.com/2016/09/08/wordpress-https-redirection/">WordPress HTTPS Redirection</a> first appeared on <a href="https://xploit29.com">xploit29</a>.]]></content:encoded>
					
					<wfw:commentRss>https://xploit29.com/2016/09/08/wordpress-https-redirection/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4</post-id>	</item>
		<item>
		<title>Scaling Django Properly</title>
		<link>https://xploit29.com/2016/09/08/scaling-django-properly/</link>
					<comments>https://xploit29.com/2016/09/08/scaling-django-properly/#respond</comments>
		
		<dc:creator><![CDATA[Irving Kcam]]></dc:creator>
		<pubDate>Thu, 08 Sep 2016 22:42:14 +0000</pubDate>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Learn]]></category>
		<category><![CDATA[Scaling]]></category>
		<guid isPermaLink="false">http://www.xploit29.com/?p=9</guid>

					<description><![CDATA[<p>I&#8217;m in love with Django and as a love we should be able to know how to scale Django properly that&#8217;s why I&#8217;m sharing this video with you. So you can make your Django deployment &#8220;greater again&#8221; (no pun intended).</p>
The post <a href="https://xploit29.com/2016/09/08/scaling-django-properly/">Scaling Django Properly</a> first appeared on <a href="https://xploit29.com">xploit29</a>.]]></description>
										<content:encoded><![CDATA[<p><iframe loading="lazy" width="560" height="315" src="https://www.youtube.com/embed/Ul-pHtOfA9U" frameborder="0" allowfullscreen></iframe></p>
<p>I&#8217;m in love with Django and as a love we should be able to know how to scale Django properly that&#8217;s why I&#8217;m sharing this video with you. So you can make your Django deployment &#8220;greater again&#8221; (no pun intended).</p>The post <a href="https://xploit29.com/2016/09/08/scaling-django-properly/">Scaling Django Properly</a> first appeared on <a href="https://xploit29.com">xploit29</a>.]]></content:encoded>
					
					<wfw:commentRss>https://xploit29.com/2016/09/08/scaling-django-properly/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">9</post-id>	</item>
	</channel>
</rss>
