Skip to content

Instantly share code, notes, and snippets.

View duboisf's full-sized avatar

Fred Dubois duboisf

View GitHub Profile
@duboisf
duboisf / closure_example.py
Created April 22, 2010 00:52
simple closure example in python
class Value:
def __init__(self, val):
self.val = val
def invoker(x):
def closure(y):
print (x.val + y)
return closure
anObject = Value(5)
@duboisf
duboisf / WhileClosure.scala
Created April 22, 2010 01:20
Creating a while loop function
object WhileClosure extends Application {
def While(cond: => Boolean)(body: => Unit): Unit = {
if (cond) {
body
While(cond)(body)
}
}
var x = 0
@duboisf
duboisf / tail.hs
Created April 28, 2010 12:32
tail.hs
import System.Environment (getArgs)
main =
getArgs >>= \[nbLines, filename] ->
lines `fmap` readFile filename >>= \contents ->
mapM_ putStrLn (drop (length contents - (read nbLines :: Int)) contents)
@duboisf
duboisf / tail.scala
Created April 28, 2010 12:33
tail.scala
import scala.io.Source
import java.io.File
object Tail {
def main(args: Array[String]) {
val filesource = Source.fromFile(new File(args(1)))
val lines = filesource.getLines().toList
lines.drop(lines.length - args(0).toInt).map(println)
filesource.close()
}
@duboisf
duboisf / Build.scala
Created June 14, 2011 10:59
sbt uninitialized sources setting
import sbt._
import Keys._
object Test extends Build {
lazy val listSources = TaskKey[Unit]("list-sources")
def listSourcesTask =
listSources <<= sources map { _ foreach println }
@duboisf
duboisf / describe.scala
Created September 7, 2011 01:29
Example of using stripMargin
package gitjira.actions
import gitjira.{Configuration, JIRA}
case class DescribeAction(number: Int) extends GitJiraAction {
def execute(config: Configuration, jira: JIRA) {
val issue = jira getIssue number
val output = """Issue: %s

Keybase proof

I hereby claim:

  • I am duboisf on github.
  • I am duboisf (https://keybase.io/duboisf) on keybase.
  • I have a public key ASBf_c8uO1Jj2wnFif-u4NuMe0xaCoynHsxksokHMWoSXQo

To claim this, I am signing this object:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: test-
namespace: argo
spec:
entrypoint: reproduce
arguments:
parameters:
@duboisf
duboisf / safe_userpass_token
Created May 17, 2019 13:00
Safely store a username and password for kubectl using pass
#!/bin/bash
# This script is intented to be used with kubectl when you don't want a plain
# base64 encoded username:password token in your kube config.
# It uses pass (https://www.passwordstore.org/) to store your password securely.
#
# To use it, download this script, make it executable (chmod +x
# safe_userpass_token) move it to the ~/.kube/bin folder (create it if it
# doesn't exist) and configure an entry in your ~/.kube/config under users,
# like so:
@duboisf
duboisf / openconnect_vpn_inside_netns.sh
Last active January 30, 2024 23:41 — forked from nehaljwani/openconnect_vpn_inside_netns.sh
OpenConnect VPN Inside Linux Network Namespace
#!/bin/bash
# start openconnect tunnel and shell inside Linux network namespace
#
# this is a fork of schnouki's script, see original blog post
# https://schnouki.net/posts/2014/12/12/openvpn-for-a-single-application-on-linux/
#
# original script can be found here
# https://gist.github.com/Schnouki/fd171bcb2d8c556e8fdf
# ------------ adjust values below ------------