Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
lbvf50mobile / fileutils_example.rb
Created January 9, 2019 19:18 — forked from jensendarren/fileutils_example.rb
An example of using FileUtils in Ruby
require 'fileutils'
# __FILE__ keyword in ruby
puts "The current ruby file being executed is #{__FILE__}"
# Gets the directory name of the file being executed
current_directory = File.dirname(__FILE__)
puts "The current directory is #{current_directory}"
# expands to reveal the pwd (Present working directory)
@lbvf50mobile
lbvf50mobile / gist:a90665a0e927a1be009706fe6ca2bc7a
Created April 3, 2019 15:26 — forked from mozamimy/gist:52c0004c8370f78df2c2
Validations for IP address and MAC address on Ruby on Rails
require "resolv"
class Model < ActiveRecord::Base
validates :ip_address, format: { with: Resolv::IPv4::Regex }
validates :mac_address, format: { with: /\A([0-9A-F]{2}[-:]){5}([0-9A-F]{2})\z/ }
end
@lbvf50mobile
lbvf50mobile / each_slice.js
Created May 2, 2019 11:11 — forked from SauloSilva/each_slice.js
Each slice javascript
// without callback
Array.prototype.eachSlice = function (size){
this.arr = []
for (var i = 0, l = this.length; i < l; i += size){
this.arr.push(this.slice(i, i + size))
}
return this.arr
};
[1, 2, 3, 4, 5, 6].eachSlice(2)
// https://developer.mozilla.org/ja/New_in_JavaScript_1.7#Array_comprehensions
function range (begin, end) {
for (let i = begin; i < end; ++i) {
yield i;
}
};
// http://code.activestate.com/recipes/347689-ruby-arrayeach_cons-each_slice-overlapping-and-non/
function each_cons (l, n) {
return [l.slice(i, i + n) for (i in (range(0, l.length - n + 1)))]

Lambda: standard

# Creating a lambda
l = lambda { |name| "Hi #{name}!" }

# Executing the lambda
l.call("foo") # => Hi foo!
@lbvf50mobile
lbvf50mobile / check-substring-starts-with.go
Created September 4, 2019 15:00 — forked from flaviocopes/check-substring-starts-with.go
Go: check if a string starts with a substring #golang
package main
import (
"strings"
)
func main() {
strings.HasPrefix("foobar", "foo") // true
}
@lbvf50mobile
lbvf50mobile / gist_to_github_repo.md
Created November 2, 2019 15:59 — forked from ishu3101/gist_to_github_repo.md
Transfer a gist to a GitHub repository

Transfer a gist to a GitHub repository

clone the gist

git clone https://gist.github.com/ishu3101/6fb35afd237e42ef25f9

rename the directory

mv 6fb35afd237e42ef25f9 ConvertTo-Markdown

change the working directory to the newly renamed directory

cd ConvertTo-Markdown

@lbvf50mobile
lbvf50mobile / README.md
Created April 29, 2021 10:47 — forked from miguelmota/README.md
Multiple accounts with Mutt E-Mail Client (gmail example)

How to set up multiple accounts with Mutt E-mail Client

Thanks to this article by Christoph Berg

Instructions

Directories and files

~/
@lbvf50mobile
lbvf50mobile / ruby_books.md
Created September 20, 2021 07:01 — forked from baweaver/ruby_books.md
A list of books for learning and expanding on your Ruby knowledge.

Ruby Book List

Learning Ruby

You're taking your first steps into Ruby

A good introduction to programming in general. Easy on newer programmers.

@lbvf50mobile
lbvf50mobile / bash_strict_mode.md
Created May 8, 2022 15:57 — forked from vncsna/bash_strict_mode.md
set -e, -u, -o, -x pipefail explanation

set -e, -u, -o, -x pipefail

The set lines

  • These lines deliberately cause your script to fail. Wait, what? Believe me, this is a good thing.
  • With these settings, certain common errors will cause the script to immediately fail, explicitly and loudly. Otherwise, you can get hidden bugs that are discovered only when they blow up in production.
  • set -euxo pipefail is short for:
set -e
set -u