Skip to content

Instantly share code, notes, and snippets.

View define_urldecode_bash_function.sh
# usage: $ urldecode https%3A%2F%2Fgoogle.com%2Fsearch%3Fq%3Durldecode%2Bbash
# result: https://google.com/search?q=urldecode+bash
urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
@sebasbad
sebasbad / URL+Query.swift
Last active Jan 2, 2017
URL swift extension to get query parameter values array (adapted from https://gist.github.com/InsertNetan/372c9f51549ea96e5af2)
View URL+Query.swift
import Foundation
extension URL {
func queryItemValues(key: String) -> [String?]? {
guard let components = NSURLComponents(url: self, resolvingAgainstBaseURL: false) else {
return nil
}
guard let queryItems = components.queryItems else { return nil }
return queryItems.filter {
View rubySha256.rb
require 'digest'
File.foreach("emails.txt").with_index do |line|
strippedLine = "#{line}".strip
lineSha256 = Digest::SHA256.hexdigest strippedLine
puts "#{strippedLine},#{lineSha256}"
end
#usage: ruby rubySha256.rb > emailsSha256.txt
View keybase.md

Keybase proof

I hereby claim:

  • I am sebasbad on github.
  • I am sebasbad (https://keybase.io/sebasbad) on keybase.
  • I have a public key ASC7VfZaW1Q5kMLdfSpwHHehsI7lM61Wwy8KccBKMVxegwo

To claim this, I am signing this object:

@sebasbad
sebasbad / pre-commit
Created Jun 15, 2018 — forked from edgar/pre-commit
Git: Pre-commit git hook that prevents commits with undesired words, usually debugging statements #git #hook #pre-commit
View pre-commit
# This script verifies if a list of "undesired" words are presented in the files you are intended to commit such console
# output, debugging information or keys/tokens/passwords
# Based on the git hook created by Mark Story
# http://mark-story.com/posts/view/using-git-commit-hooks-to-prevent-stupid-mistakes
# Instructions:
# Put this file into your .git/hooks folder and set as executable (chmod +x pre-commit)
@sebasbad
sebasbad / countCertainDays.js
Last active Feb 20, 2019
Count certain days of the week between two dates
View countCertainDays.js
// https://stackoverflow.com/questions/25562173/calculate-number-of-specific-weekdays-between-dates
// days is an array of weekdays: 0 is Sunday, ..., 6 is Saturday
function countCertainDays( days, d0, d1 ) {
var ndays = 1 + Math.round((d1-d0)/(24*3600*1000));
var sum = function(a,b) {
return a + Math.floor( ( ndays + (d0.getDay()+6-b) % 7 ) / 7 ); };
return days.reduce(sum,0);
}
@sebasbad
sebasbad / TOTP.java
Created Apr 22, 2020 — forked from xandkar/TOTP.java
TOTP reference implementation from RFC 6238
View TOTP.java
/**
Copyright (c) 2011 IETF Trust and the persons identified as
authors of the code. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, is permitted pursuant to, and subject to the license
terms contained in, the Simplified BSD License set forth in Section
4.c of the IETF Trust's Legal Provisions Relating to IETF Documents
(http://trustee.ietf.org/license-info).
*/
@sebasbad
sebasbad / cors-nginx.conf
Created May 7, 2020 — forked from alexjs/cors-nginx.conf
Slightly tighter CORS config for nginx
View cors-nginx.conf
#
# Slightly tighter CORS config for nginx
#
# A modification of https://gist.github.com/1064640/ to include a white-list of URLs
#
# Despite the W3C guidance suggesting that a list of origins can be passed as part of
# Access-Control-Allow-Origin headers, several browsers (well, at least Firefox)
# don't seem to play nicely with this.
#