Skip to content

Instantly share code, notes, and snippets.

View ivanionut's full-sized avatar
🎯
Focusing

Ivan Ionut ivanionut

🎯
Focusing
View GitHub Profile
<cfscript>
// If you don't set this then the searchParams structure will be uppercased when converted to JSON and cause ElasticSearch to error.
processingdirective preserveCase="true";
public struct function elasticSearchSearch( required string serverURL,
required struct searchParams,
required string index,
required string type) {
// Post the search parameters to the ElasticSearch index and type
http method="post" url="#arguments.serverURL#/#arguments.index#/#arguments.type#/_search" result="searchResponse" {
<cfscript>
// Query to retrieve some data from the database
variables.myData = queryExecute(
sql = "
SELECT *
FROM myTable
LIMIT 10
",
options = {datasource="#Application.myDSN#"}
);
@JamoCA
JamoCA / isEmailDomainValid.cfm
Last active April 10, 2018 18:43
ColdFusion UDF to validate if an email address' MX record exists. (Spammers tend to generate random domain strings when submitting comment spam.)
<!--- NOTE: This technique is not 100% accurate because some DNS servers don't allow MX queries or may be slow to respond,
but this will identify addresses that are potentially bad or suspicious. --->
<cfscript>
function isEmailDomainValid(email){
var local.email = arguments.email;
var local.DNSServer = '8.8.8.8'; /* Google DNS */
var local.timeout = 2000;
var local.attempts = 1;
var local.valid = true;
var local.emailDomain = trim(listlast(local.email,'@'));
@JamoCA
JamoCA / isAjaxRequest.cfm
Last active August 29, 2015 14:01
This ColdFusion 8-11 UDF will query the server's request headers to determine if the request is an Ajax form post from jQuery. (jQuery adds a special header to all ajax requests.)
<!-- Compatible with ColdFusion 8-11.
4/28/2015 Rewritten to compensate for new undocumented CF10/11 behavior regarding getHTTPRequestData().
https://bugbase.adobe.com/index.cfm?event=bug&id=3042675
https://bugbase.adobe.com/index.cfm?event=bug&id=3581691
http://www.bennadel.com/blog/2824-gethttprequestdata-may-break-your-request-in-coldfusion-but-gethttprequestdata-false-may-not.htm
--->
<cffunction name="isAjaxRequestPost" output="false" returntype="boolean" access="public">
<cfset var response = StructNew()>
<cfset response.AjaxHeader = getPageContext().getRequest().getHeader("X-Requested-With") />
@JamoCA
JamoCA / JsoupTableParse.cfm
Last active March 11, 2016 08:52
Sample ColdFusion script to parse a webpage and extract table data using jsoup.
<cfhttp url="http://target_website_with-table.com/" username="#CGI.Http_User_Agent#"></cfhttp>
<cfscript>
jsoup = CreateObject("java", "org.jsoup.Jsoup");
HTMLDocument = jsoup.parse(CFHTTP.fileContent);
/* Identify a specific table containing the data to scrape */
TheTable = HTMLDocument.select("##tableByID");
/* Alternate DOM select methods if table doesn't have a unique ID
@tompave
tompave / nginx.conf
Last active August 6, 2024 13:21
commented nginx.conf for Ruby on Rails
# A commented nginx configuration file for Ruby on Rails
#
# Author: Tommaso Pavese
# [email protected]
# http://tommaso.pavese.me
#
# License: http://www.wtfpl.net/
#
#
# Tested with:
@sigmaprojects
sigmaprojects / ImageManipulation.cfc
Created January 19, 2014 20:06
A collection of image manipulation methods packaged in a ColdBox plugin. Most of the credit goes to Sean Corfield, Ben Nadel, and http://cfsearching.blogspot.com/
<cfcomponent name="ImageManipulation" hint="Image manipulation functions." extends="coldbox.system.plugin" output="false" cache="false">
<cfproperty name="imageObj" type="any" />
<cfset variables.instance = StructNew() />
<cffunction name="init" access="public" returntype="ImageManipulation" output="false">
<cfargument name="controller" type="any" required="true">
<cfset super.Init(arguments.controller) />
<cfset setpluginName("ImageManipulation")>
@denji
denji / nginx-tuning.md
Last active May 14, 2025 02:43
NGINX tuning for best performance

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 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading 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.

@cflove
cflove / httpGet.cfm
Last active April 25, 2017 13:01
Get large file over HTTP. CFHTTP in some cases seems not to respect timeout attribute values and time out prematurely. CFHTTP collect the file into the memory and write to the hard drive at the end. That enables large files to create an OutOfMemoryError error. This should solve both of those options.
<cffunction name="httpget" access="private" returnType="any" output="No">
<cfargument name ="source" type="string" required="true"/>
<cfargument name ="destination" type="string" required="true"/>
<cfargument name ="ConnectTimeout" type="numeric" required="false" default="10" hint="Time Out in Seconds"/>
<cfargument name ="ReadTimeout" type="numeric" required="false" default="60" hint="Time Out in Seconds" />
<cfargument name ="dimensions" type="numeric" required="false" default="255"/>
<cfset local.urlconnection = createObject("java", "java.net.URL").init(arguments.source)>
<cfset local.connection = local.urlconnection.openConnection() />
<cfset local.connection.setConnectTimeout(javaCast("int",arguments.ConnectTimeout*1000)) />
@aviris
aviris / Tab out of Autocomplete Pairs
Created November 12, 2013 23:24
Tab out of paired characters in Sublime Text (e.g. "",{},[],(),**,__, etc.).
[
{ "keys": ["tab"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
[
{ "key": "following_text", "operator": "regex_contains", "operand": "^[)\"\\]*_}]", "match_all": true },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
]
}
]