Skip to content

Instantly share code, notes, and snippets.

@stuntgoat
stuntgoat / ex.go
Last active January 12, 2017 16:45
Raw JSON URL string from json marshal of a struct
package main
import (
`bytes`
`fmt`
`net/url`
`encoding/json`
)
type Ex struct {
function checkPalindrome(str) {
return str == str.split('').reverse().join('');
}
function gen_key(a, b) {
if (a <= b) {
return a + '*' + b;
}
return b + '*' + a;
}
import io
import logging
logging.getLogger('googleapiclient.discovery').setLevel(logging.WARNING)
logging.getLogger('oauth2client.client').setLevel(logging.WARNING)
from apiclient.discovery import build
from apiclient.http import (
MediaIoBaseDownload,
MediaFileUpload,
)
import sys
from time import sleep
from lockfile.pidlockfile import PIDLockFile
if __name__ == '__main__':
# If we can't acquire a lock in 1 second, raise an exception.
with PIDLockFile('/home/me/script.pid', timeout=1):
while True:
sys.stdout.write('Check /home/me/script.pid for my process id\n')
mkdir bash-fix
cd bash-fix
curl https://opensource.apple.com/tarballs/bash/bash-92.tar.gz | tar zxf -
cd bash-92/bash-3.2
curl https://ftp.gnu.org/pub/gnu/bash/bash-3.2-patches/bash32-052 | patch -p0
cd ..
xcodebuild
sudo cp /bin/bash /bin/bash.old
sudo cp /bin/sh /bin/sh.old
build/Release/bash --version # GNU bash, version 3.2.52(1)-release
/**
Here's an example of failing to return the correct type
*/
object CovarianceExampleFailFirst {
/**
Covariance example (does not compile)
def mixFoods[T >: Watermelon](food: T): List[T] = {
/**
Here is an object that has a method mixFoods which will accept
a subclass of a GardenItem and return a list of either
GardenItems or subclasses of GardenItems.
*/
object CovarianceExample {
/**
Covariance example (compiles)
@stuntgoat
stuntgoat / Base.scala
Last active August 29, 2015 14:06
The base classes.
class Dirt
class GardenItem extends Dirt {
val flavor = "seedy"
}
class Cucumber extends GardenItem {
override val flavor = "bland"
}
/** Base class, since all things from the produce department come from a garden. */
class GardenItem {
val flavor = "seedy"
}
@stuntgoat
stuntgoat / stop_queries.sql
Last active August 29, 2015 14:03
Check long running queries and stop them if you want.
;; Show long running queries.
SELECT pid, state, query_start, query FROM pg_stat_activity;
;; Kill a long running query.
SELECT pg_cancel_backend(<pid of the query from previous query>);