This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import functools | |
| import time | |
| def hash_object(obj): | |
| if isinstance(obj, (tuple, list)): | |
| return (type(obj), tuple([hash_object(it) for it in obj])) | |
| elif isinstance(obj, dict): | |
| return (type(obj), tuple([(k, hash_object(v)) | |
| for (k, v) in obj.iteritems()])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package maxsum | |
| import "math" | |
| func MaxSum1(v []float64) (maxSofar float64) { | |
| length := len(v) | |
| for i := 0; i < length; i++ { | |
| for j := i; j < length; j++ { | |
| sum := 0.0 | |
| // sum of [i..j] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package search | |
| // binary search 1: low ≤ mid < high | |
| func BinarySearch1(list []int, v int) int { | |
| low, high := 0, len(list) | |
| for low < high { | |
| mid := (high-low)/2 + low | |
| // low ≤ mid < high | |
| if list[mid] < v { | |
| low = mid + 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # https://your-team.slack.com/services/new/incoming-webhook | |
| WEBHOOK_URL='' | |
| CHANNEL='#dev' | |
| USERNAME='sentry' | |
| iCON_URL='https://slack.global.ssl.fastly.net/17635/img/services/sentry_128.png' | |
| function post_message() { | |
| payload="{'username': '$USERNAME', 'text': '$AT_USER $1', 'channel': '$CHANNEL', 'icon_url': '$ICON_URL'}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- ALTER TABLE users ADD COLUMN deleted boolean NOT NULL DEFAULT false; | |
| ALTER TABLE users ADD COLUMN deleted boolean; | |
| ALTER TABLE users ALTER COLUMN deleted SET DEFAULT false; | |
| UPDATE users SET deleted = false WHERE deleted IS NULL; | |
| ALTER TABLE users ALTER COLUMN deleted SET NOT NULL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "crypto/hmac" | |
| "crypto/sha1" | |
| "encoding/base64" | |
| "fmt" | |
| "io" | |
| "log" | |
| "net/http" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| x=0 | |
| while [ $x -lt 5432 ]; do | |
| prev=$(expr $x \* 1000000) | |
| next=$(expr $(expr $x + 1) \* 1000000) | |
| echo $(date +'%Y-%m-%d %H:%M:%S'), $prev, $next | |
| x=$(expr $x + 1) | |
| psql -c "UPDATE followships SET is_deleted = false WHERE is_deleted IS NULL and id >= $prev and id <= $next;" | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1 | Canada | |
| 1 | United States | |
| 20 | Egypt | |
| 211 | South Sudan | |
| 212 | Morocco | |
| 213 | Algeria | |
| 216 | Tunisia | |
| 218 | Libya | |
| 220 | Gambia | |
| 221 | Senegal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python2 | |
| # -*- coding: utf-8 -*- | |
| import json | |
| import urllib | |
| import urllib2 | |
| def bearychat(url, text, channel=None, markdown=None, attachments=None): | |
| payload = { | |
| 'text': text, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python2 | |
| # -*- coding: utf-8 -*- | |
| import datetime | |
| import functools | |
| import time | |
| # logging | |
| # ======= |