Skip to content

Instantly share code, notes, and snippets.

View beekalam's full-sized avatar
🐝
Focusing

Mohammad Reza Mansouri beekalam

🐝
Focusing
View GitHub Profile
@beekalam
beekalam / str-at-point.el
Last active March 19, 2022 14:29
string between two quotation marks
; @snippet.elisp.string
(defun str-at-point ()
"read string in quotes"
(interactive)
(save-excursion
(let ($skipchars $p1 $p2)
(setq $skipchars "^'\"`")
(skip-chars-backward $skipchars)
(setq $p1 (point))
(skip-chars-forward $skipchars)
@beekalam
beekalam / convert-to-camelcase.go
Created March 17, 2022 15:05
convert to camel case
// @snippet.string convert to camel case
func ToCamelCase(input string) string {
titleSpace := strings.Title(strings.Replace(input, "_", " ", -1))
camel := strings.Replace(titleSpace, " ", "", -1)
return strings.ToLower(camel[:1]) + camel[1:]
}
@beekalam
beekalam / pad-string.go
Created March 17, 2022 15:00
pad string
// @snippet.string pad string
func PadString() {
needSpace := "need space"
fmt.Println(pad(needSpace, 14, "CENTER"))
fmt.Println(pad(needSpace, 14, "LEFT"))
}
func pad(input string, padLen int, align string) string {
inputLen := len(input)
@beekalam
beekalam / trim-ws.go
Created March 17, 2022 14:55
trim whitespace
// @snippet.string trim white space
func StringTrimeSpace() {
stringToTrim := "\t\t\n Go \tis\t Awesome \t\t" //
trimResult := strings.TrimSpace(stringToTrim)
fmt.Println(trimResult) //Go is Awesome
}
// @snippet.string.regex replace whitespace with regex
func StringTrimRegex() {
stringWithSpaces := "\t\t\n Go \tis\n Awesome \t\t"
@beekalam
beekalam / log-to-syslog.go
Created March 17, 2022 14:51
log to syslog
// @snippet.logging log to syslog
func LogToSyslog() {
sysLog, err := syslog.New(syslog.LOG_SYSLOG, "systemlog.go")
if err != nil {
log.Println(err)
return
} else {
log.SetOutput(sysLog)
log.Print("Everything is fine")
}
@beekalam
beekalam / index-of-substring.go
Created March 17, 2022 14:49
index of substring
// @snippet.string indexOf substring
func IndexOfSubstring() {
strings.Index("Japan", "abc") //-1 Index of first abc
strings.IndexAny("Japan", "abc") // 1 a,b or c
strings.LastIndex("Japan", "abc") // -1 index of last abc
strings.LastIndexAny("Japan", "abc") // 3 a,b or c
}
@beekalam
beekalam / sort-string.go
Created March 17, 2022 14:46
sort string
// @snippet.string.sort sort string
func SortString() {
w := "anagram"
s := strings.Split(w, "")
sort.Strings(s)
res := strings.Join(s, "")
fmt.Printf("SortString(): %v\n", res)
}
@beekalam
beekalam / reverse-string.go
Created March 17, 2022 14:45
reverse string
// @snippet reverse string
func StrReverse(s string) string {
var sb strings.Builder
for i := len(s) - 1; i >= 0; i-- {
fmt.Fprintf(&sb, "%c", s[i])
}
return sb.String()
}
func ReverseString(s string) string {
@beekalam
beekalam / executiong-time.go
Created March 17, 2022 12:34
script execution time
func ScriptExecutionTime() {
start := time.Now()
fmt.Println("The Script started at :", start)
fmt.Println("Saving the world....")
time.Sleep(2 * time.Second)
end := time.Now()
fmt.Println("The Script completed at: ", end)
}
@beekalam
beekalam / convert.go
Created March 17, 2022 12:31
convert string to number
// @snippet.string.number convert string to numbers
func ConvertStringToNumber() {
const bin = "00001"
const hex = "2f"
const intString = "12"
const floatString = "12.3"
// @snippet.number parse integer Decimals
res, err := strconv.Atoi(intString)
if err != nil {