Skip to content

Instantly share code, notes, and snippets.

View vikramj74's full-sized avatar
🎯
Focusing

Vikram Jaswal vikramj74

🎯
Focusing
View GitHub Profile
@vikramj74
vikramj74 / string_helpers.go
Created December 28, 2017 07:00
Clip string from beginning and end : golang
package string_helpers
import (
"fmt"
)
func ClipStringFromEnds(s string, n int) string {
return s[n : len(s)-n]
}
<?php
/**
* Returns a simple formatted string which maybe printed in a log file
* @param $params array
*/
function getFormattedLogString($params) {
$timeStamp = date('Y-m-d H:i:s');
return "\n".$timeStamp.'!~!'.json_encode($params);
}
<?php
class Utils {
public static function getJsonFromQueryResult($qr) {
$arr = array();
while($row = $result->fetch_assoc()) {
$arr[] = $row;
}
return json_encode($arr);
}
package debuggin_helpers;
import (
"fmt"
)
func RepresentType(t interface{}) string {
return fmt.Sprintf("--> %#v", t)
}
package main
import (
"time"
)
func FormatToStandardTimeString(givenTime time.Time) (string) {
return givenTime.Format("2006-01-02 15:04:05")
}
grep -Rc "$1" ./ | grep -v ":0" ;
<?php
namespace LoggerPlus;
class LoggerPlus
{
public static function writeDatewiseLog($logdir, $filename, $logstr)
{
$logstr .= "\n";
if (is_dir($logdir . date('Y'))) {
#! /bin/bash
# An array containing all the paths that
# need to be added to the $PATH variable
PATHS2ADD=( \
"/home/vikram/scripts" \
)
# Loop over the array and
# and add all the paths to
<?php
class SequentialLogReader {
private $basePath;
private $logFileName;
private $dayWindow;
private $timeWindow;
private $logProcessor;
public function __construct($basePath, $logFileName, $timeWindow, $dateOffset = null,$dateFormat = null) {
#! /usr/local/bin/bash
# A simple utitlity to SSH easily into remote servers
# You can assign nick names to the IPs, and then use
# the nick to SSH into the particular server
declare -A ips=( \
[izPanel]=35.185.138.140 \
[izRepo]=35.196.99.250 \
);