Skip to content

Instantly share code, notes, and snippets.

@augustyip
augustyip / parameterized_sql_query.asp
Last active December 8, 2022 04:18
ASP Classic VBscript Parameterized SQL Query
<%
Dim CONN
Set CONN = server.CreateObject("ADODB.Connection")
CONN.Open connstr
Dim CMD
set CMD = server.CreateObject("ADODB.Command")
set CMD.ActiveConnection = CONN
<?php
class OrderController extends ControllerBase implements ContainerInjectionInterface {
...
/**
* Checkout an order.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request.
#!/bin/sh
if [ ! $(id -ru) -eq 0 ]; then
echo "You must run this as root."
exit
fi
for SERVICE in php5-fpm hhvm nginx varnish mysql memcached
do
service $SERVICE restart
@augustyip
augustyip / gist:e66cfa048d5186879ada
Created October 13, 2014 03:17
Convert the csv file to array.
<?php
/**
* Convert the csv file to array.
* @param string $filename
* @param string $delimiter
* @return Array
*/
function isc_data_csv_to_array($filename='', $delimiter=',') {
if(!file_exists($filename) || !is_readable($filename)) {
return FALSE;
@augustyip
augustyip / gist:6f48ae39ded3501bf771
Created September 16, 2014 08:34
drupal: create the custom term if not exist.
<?php
function get_term_tid($term_name, $vocabulary){
$terms = taxonomy_get_term_by_name($term_name, $vocabulary->machine_name);
if (empty($terms)) {
$term = create_term($term_name, $vocabulary);
return $term->tid;
} else {
return reset($terms)->tid;
}
}
@augustyip
augustyip / gist:9b730e9a6aabfd00d1e0
Last active August 29, 2015 14:03
Linux Commands
#Copy Files With Rsync Over SSH
rsync -avz -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress /root/bigfile.txt username@198.211.117.129:/
# Mysql search tables
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'drupal_bcsiem' AND TABLE_NAME LIKE "commerce%";
# Export only modified and added files with folder structure in Git
@augustyip
augustyip / gist:1036acee73040af8008a
Created June 25, 2014 04:17
Break x,y,z and x+y+z into an array. Numeric only.
/*
* Break x,y,z and x+y+z into an array. Numeric only.
*
* @param $str
* The string to parse.
*
* @return $object
* An object containing
* - operator: Either 'and' or 'or'
* - value: An array of numeric values.
<?php
Class perRequestCache {
private static $cache = array();
public static function get($key) {
return self::$cache[$key];
}
public static function set($key, $value) {
@augustyip
augustyip / gist:3dd57bca5a07190d873f
Created June 11, 2014 09:25
Adding a parameter to the URL with JavaScript
function addParam(url, param, value) {
var a = document.createElement('a'), regex = /[?&]([^=]+)=([^&]*)/g;
var params = {}, match, str = []; a.href = url; value=value||"";
while (match = regex.exec(a.search))
if (param != match[1]) str.push(match[1] + "=" + match[2]);
str.push(encodeURIComponent(param) + "=" + encodeURIComponent(value));
a.search = (a.search.substring(0,1) == "?" ? "" : "?") + str.join("&");
return a.href;
}
@augustyip
augustyip / gist:f0c6b532ca0b303820a7
Created May 20, 2014 04:07
To get a nested tree in Drupal 7
<?php
function taxonomy_get_nested_tree($terms = array(), $parent = 0, $parents_index = array(), $max_depth = NULL, $depth = 0) {
foreach ($terms as $term) {
foreach ($term->parents as $term_parent) {
if ($term_parent == $parent) {
$return[$term->tid] = $term;
}
else {
$parents_index[$term_parent][$term->tid] = $term;
}