Skip to content

Instantly share code, notes, and snippets.

View ivanionut's full-sized avatar
🎯
Focusing

Ivan Ionut ivanionut

🎯
Focusing
View GitHub Profile
@ivanionut
ivanionut / 0_reuse_code.js
Last active August 29, 2015 14:09
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
<!--- STEP 1 - ?event=shop-cart.cfm --->
<cfscript>
stDetails = structNew();
stDetails.cartTotal = 200.00;
stDetails.invoiceno = 3;
</cfscript>
<cfhttp url="https://api-3t.paypal.com/nvp" method="post">
<!--- auth --->
<cfhttpparam type="formfield" name="USER" value="#application.pp.username#" />
<cfscript>
/* ColdFusion 11 dropped the undocumented cfusion_encrypt & decrypt functions while Railo 4.2 still officially supports it.
This script will reestablish the built-in function. You can also use fusion_encrypt/decrypt (without the "c").
Based on 2005 blog post: http://www.barneyb.com/barneyblog/2005/10/28/cfusion_encryptcfusion_decrypt-udfs/ */
function fusion_binaryXOR(n1, n2){
n1 = formatBaseN(n1, 2);
n2 = formatBaseN(n2, 2);
return inputBaseN(replace(n1 + n2, 2, 0, "all"), 2);
}
function fusion_encrypt(string, key){
<cfscript>
/* Copy IsEMail.jar to java path. Download from https://code.google.com/p/isemail/downloads/list */
emails = ["test@test.com",
"valid_but_no_mx@fake-domain.com",
"valid_but_no_dns@fake-domain2.com",
"""much.more unusual""@example.com",
"john.smith@example.com(comment)",
"""first\last""@iana.org",
"first.last@com",
"""Joe.\Blow""@iana.org",
<cfscript>
/* based on info from http://googlewebmastercentral.blogspot.com/2006/09/how-to-verify-googlebot.html */
badBot = 0;
blockBadBots = 0;
ip = cgi.remote_addr;
userAgent = CGI.Http_User_Agent;
/* Sample request values */
//userAgent = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)";
//ip = "179.179.65.180"; //bad
<cfscript>
BadCookieList = [
"ASP.NET_SessionID",
"ISFIRSTVISIT",
"PHPSESSID",
"REMEMBERCOUNTRY",
"RESOURCEINFO",
"SESSIONS",
"SS_MID",
"USERINFO",
<cfparam name="FORM.username" default="" type="string" >
<cfparam name="FORM.password" default="" type="string" >
<cfif structKeyExists(FORM,"submit")>
<cfset recaptcha = FORM["g-recaptcha-response"] >
<cfif len(recaptcha)>
<cfset googleUrl = "https://www.google.com/recaptcha/api/siteverify">
<cfset secret = "6LctadUSAAAAAM7NPoPq5jlbm3a37ib3sHlRFyNE">
<cfscript>
public any function getWeekOfMonth(date d='#Now()#', numeric minDaysInFirstWeek=1) {
var cal = CreateObject('java', 'java.util.GregorianCalendar').init(
JavaCast('int', Year(arguments.d))
, JavaCast('int', Month(arguments.d)-1)
, JavaCast('int', Day(arguments.d))
, JavaCast('int', Hour(arguments.d))
, JavaCast('int', Minute(arguments.d))
, JavaCast('int', Second(arguments.d))
);
@ivanionut
ivanionut / recaptcha.cfc
Last active August 29, 2015 14:13 — forked from stevewithington/recaptcha.cfc
Google ReCAPTCHA v2 for ColdFusion / Railo / CFML. See https://github.com/stevewithington/ReCAPTCHA for example usage.
/**
* This is a CFML library that handles calling reCAPTCHA.
* - Documentation and latest version
* https://developers.google.com/recaptcha/
* - Get a reCAPTCHA API Key
* https://www.google.com/recaptcha/admin#list
* - Discussion group
* http://groups.google.com/group/recaptcha
*
* @copyright Copyright (c) 2014, Stephen J. Withington, Jr.

Nginx Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400,000 to 500,000 requests per second (clustered), most what i saw is 50,000 to 80,000 (non-clustered) requests per second and 30% CPU load, course, this was 2xIntel Xeon with HT enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

First, you will need to install nginx, my way to install nginx is compiling it from source, but for now we will use apt-get