Skip to content

Instantly share code, notes, and snippets.

View sphrak's full-sized avatar
🐱
hax

Niclas sphrak

🐱
hax
  • Stockholm, Sverige
  • 09:55 (UTC +02:00)
View GitHub Profile
@sphrak
sphrak / Jenkinsfile
Created July 17, 2018 01:33 — forked from jonico/Jenkinsfile
Example for a full blown Jenkins pipeline script with multiple stages, input steps, injected credentials, heroku deploy, sonarqube and artifactory integration, multiple Git commit statuses, PR merge vs branch build detection, REST API calls to GitHub deployment API, stage timeouts, stage concurrency constraints, ...
#!groovy
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
/*
Please make sure to add the following environment variables:
HEROKU_PREVIEW=<your heroku preview app>
HEROKU_PREPRODUCTION=<your heroku pre-production app>
HEROKU_PRODUCTION=<your heroku production app>
@sphrak
sphrak / unrar.sh
Created February 3, 2019 19:00
Extract all rar archives recursively and delete if extraction was successful
#!/bin/bash
for file in $(find . -iname '*.rar'); do
echo "Extracting ${file}..."
dir=$(dirname ${file})
unrar e -y -o+ -p- "${file}" "${dir}"
# check exit status, if not 0 it failed
@sphrak
sphrak / gradient.js
Created April 5, 2019 11:09 — forked from siamak/gradient.js
Steps in Gradient
/**
* GradientArray • Steps gradient.
* @author Siamak Mokhtari <hi@siamak.work>
* @date 06/21/16.
*/
class GradientArray {
// Convert a hex color to an RGB array e.g. [r,g,b]
// Accepts the following formats: FFF, FFFFFF, #FFF, #FFFFFF
hexToRgb(hex) {
let r, g, b, parts;
@sphrak
sphrak / bootable-windows-on-usb.md
Last active April 23, 2019 07:48
Copy windows iso contents to a usb memory and make it bootable

0. Format partition to ntfs somehow

1. Mount usb drive

mount /dev/sdX /media/usb

2. Mount iso

mount windows.iso /media/windows
@sphrak
sphrak / import-images-windows.bat
Last active May 7, 2019 09:01
Microsoft removed the standard camera import feature in windows > 7 and forces you to use their dumb app. This is what it has come down to.
@echo off
set TARGET=D:\DCIM\path
set DESTINATION=C:\path\to\photos\%date%
echo Copying images from camera %TARGET% to %DESTINATION%
echo d | xcopy /s /y %TARGET% %DESTINATION%\
echo Removing images from camera..
del /s /q "%TARGET%\*.JPG"
PAUSE
import random
from time import sleep
import pygame
class CarRacing:
def __init__(self):
pygame.init()
@sphrak
sphrak / pkglist.txt
Created September 19, 2019 06:12
Archlinux package list
acpi
acpid
alsa-firmware
alsa-utils
android-studio
android-studio-beta
android-studio-canary
android-tools
atop
audacity
@sphrak
sphrak / MaskExtension.kt
Created February 8, 2020 20:52 — forked from maiconhellmann/MaskExtension.kt
MaskExtension wrote in Kotlin
import android.support.annotation.StringDef
import android.text.Editable
import android.text.TextWatcher
import android.widget.EditText
@StringDef(PHONE_9_MASK, PHONE_8_MASK, CPF_MASK, ZIP_CODE_PT_BR, MONTH_YEAR, CREDIT_CARD)
@Retention(AnnotationRetention.SOURCE)
annotation class MaskType
const val PHONE_9_MASK = "(##) #####-####"
@sphrak
sphrak / semverdiff.sh
Last active March 5, 2020 09:55
a tiny script for outputting changelog diff between releases for (semver)
#!/bin/bash
# Usage
# chmod +x semverdiff.sh
# Get diff between 1.0.0..1.0.1
# ./semverdiff 1.0.1
get_diff() {
sed -n "/^## \[$1\]/,/^## /p" CHANGELOG.md | egrep "^(-|\s+)"
}
@sphrak
sphrak / kotlin-snippets.md
Last active May 14, 2020 18:05
kotlin-snippets

Kotlin Snippets

A tiny collection of Kotlin snippets that I find useful.

Measure Execution time

Keep in mind this is not an end all be all measurement since the jvm has indeterministic garbage collection but it can give you a general idea of whats taking time.

With return value