Skip to content

Instantly share code, notes, and snippets.

View pzelnip's full-sized avatar
🤷‍♂️

Adam Parkin pzelnip

🤷‍♂️
View GitHub Profile

Keybase proof

I hereby claim:

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

To claim this, I am signing this object:

@pzelnip
pzelnip / counting.py
Created August 25, 2016 00:36
Counting letters in a string
# From https://www.linkedin.com/groups/25827/25827-6166706414627627011
# "Today i did a simple test that you give a string to a function, and then the
# return output should count the letters sequencially; as following example:
# in: "aaaaabbbbccccccaaaaaaa" => out: "5a4b6c7a"
#
def func(input_string):
if not input_string:
return ""
if len(input_string) == 1:

iTerm2 – Useful Shortcuts (Mac OS X)

with a hat tip to Sublime Text 2 Shortcuts

The Awesome

⌘; autocomplete
⌘⌥B instant replay
⌘⌥E search across all tabs
@pzelnip
pzelnip / Example.mxml
Last active August 29, 2015 14:04
Complete example of conditional datagrid editing dependent upon associated value in row
<?xml version="1.0"?>
<!-- itemRenderers\events\EndEditEventPreventEdit.mxml -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
initialize="init()">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
@pzelnip
pzelnip / The MXML Definition of the datagrid
Created August 1, 2014 15:54
Conditional Datagrid cell editing
<mx:DataGrid id="myGrid"
editable="true"
itemEditBeginning="disableEditing(event)">
<!-- definition of columns & such here -->
</mx:DataGrid>
@pzelnip
pzelnip / gist:6080964
Last active December 20, 2015 05:49
Creating a static temporary directory as suitable for use in a JUnit @DataPoints method. Based upon the advice at: http://stackoverflow.com/a/17846991/808804
private static File tmpDir;
@BeforeClass
public static void setUp() {
String dirname = UUID.randomUUID().toString().replace("-", "");
tmpDir = new File(System.getProperty("java.io.tmpdir"), dirname);
if (!tmpDir.exists()) {
tmpDir.mkdir();
}
}
@pzelnip
pzelnip / gist:5528969
Created May 6, 2013 23:02
Getting what the grading system gave me.
import sys
lines = []
for i in range(1, len(sys.argv)):
lines.append("================================== START OF sys.argv%s==========================\n" % i)
with open(sys.argv[i]) as fobj:
for line in fobj:
lines.append(line.decode('utf-8'))
lines.append("================================== END OF sys.argv%s==========================\n" % i)
@pzelnip
pzelnip / gist:5303912
Created April 3, 2013 18:38
Maxing out CPU cores
import java.util.ArrayList;
import java.util.List;
public class TestTest implements Runnable {
public static void main(String [] args) throws InterruptedException {
List<Thread> threads = new ArrayList<Thread>();
for (int x = 0; x < 10; x++) {
@pzelnip
pzelnip / gist:3139645
Created July 18, 2012 23:20
Counting number of elements in a list that meet criteria
from timeit import Timer
if __name__ == "__main__":
setup = 'x = list(range(100000))'
num_iter = 1000
print(Timer('sum(1 for item in x if item % 2 == 0)', setup).timeit(num_iter))
print(Timer('len([item for item in x if item % 2 == 0])', setup).timeit(num_iter))
# prints (on my machine):
# 12.4215...
@pzelnip
pzelnip / tryexcept_vs_isinstance.py
Created June 18, 2012 21:50
Showing that try/except is slower than isinstance
'''
Example showing that isinstance checks are faster than doing a "it's better to ask for forgiveness than
permission approach.
'''
from timeit import Timer
# Silly timing code that can be ignored
def timeruns(runs, num_iterations = 100):
return [(label, Timer(cmd, imports).timeit(num_iterations))