Skip to content

Instantly share code, notes, and snippets.

Pedro Gabriel PeteGabriel

Block or report user

Report or block PeteGabriel

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@PeteGabriel
PeteGabriel / settings.json
Created Sep 17, 2019
VS Code JS settings
View settings.json
{
"workbench.activityBar.visible": true,
"editor.lineHeight": 0,
"files.autoSave": "onFocusChange",
"editor.fontLigatures": true,
"editor.smoothScrolling": true,
"editor.mouseWheelZoom": true,
"workbench.sideBar.location": "right",
"editor.autoClosingBrackets": "always",
"mocha.files.ignore": [
@PeteGabriel
PeteGabriel / Parenthesis.cs
Created Dec 4, 2018
Get closing parenthesis for opening position
View Parenthesis.cs
public class Parenthesis
{
public static int GetClosingParenthesis(string input, int openingPos)
{
var counter = 0;
var positionFound = -1;
for (int i = 0; i < input.Length; i++)
{
if (input[i] == '(' && openingPos == i)
{
@PeteGabriel
PeteGabriel / method_calls.go
Last active Aug 15, 2018
Example of method calls in GO
View method_calls.go
package main
import (
"fmt"
)
func main() {
//Declare a pointer of type Human
peter := new(Human)
//The compile will dereference the pointer to make the call
@PeteGabriel
PeteGabriel / Extensions.swift
Created Jun 17, 2018
Create an UIColor from HEX values
View Extensions.swift
extension UIColor {
convenience init(rgb:UInt, alpha:CGFloat = 1.0) {
self.init(
red: CGFloat((rgb & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgb & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgb & 0x0000FF) / 255.0,
alpha: CGFloat(alpha)
)
}
}
View remove.scala
def deleteNode(node: FrequencyNode): Unit = {
node.prev.next = node.next
node.next.prev = node.prev
node.next= null; node.prev = null
}
View access.scala
def access(key: UUID): Int = {
val tmp = this.byKey(key)
if (tmp == null) {
throw new Exception("No such key")
}
val freq = tmp.parent
var nextFreq = freq.next
if (nextFreq == this.frequencyHead || nextFreq.value != (freq.value + 1)) {
View cache_insert.scala
def insert(key: UUID, value : Int) = {
if (this.byKey.contains(key)){
throw new Exception("Key already exists")
}
val freqNode = this.frequencyHead.next
if (freqNode.value != 1){
this.frequencyHead.next = LfuCache.getNewNode(this.frequencyHead, freqNode)
this.byKey(key) = LfuItem(this.frequencyHead.next, value, key)
this.frequencyHead.next.items += this.byKey(key)
@PeteGabriel
PeteGabriel / time.scala
Created May 20, 2018
Measure time in Scala
View time.scala
object Time {
def time[A](a: => A) = {
val now = System.nanoTime
val result = a
val micros = (System.nanoTime - now) / 1000
println("%d microseconds".format(micros))
result
}
@PeteGabriel
PeteGabriel / guid.pyw
Created Apr 13, 2018
Generate a guid and copy it to clipboard (no console open)
View guid.pyw
# Install the following modules:
# pip install pyperclip
# pip install uuid
import uuid
import pyperclip
pyperclip.copy(str(uuid.uuid1()))
# On Windows systems, there is no notion of an “executable mode”.
@PeteGabriel
PeteGabriel / gen_guid.py
Created Feb 14, 2018
Generator of guid in cmd line
View gen_guid.py
import uuid
import sys
if len(sys.argv) <= 1:
print(uuid.uuid1())
else:
for x in range(0, int(sys.argv[1])):
print(uuid.uuid1())
#usage
You can’t perform that action at this time.