Skip to content

Instantly share code, notes, and snippets.

@ochoto
ochoto / r-to-python-data-wrangling-basics.md
Created June 4, 2020 16:24 — forked from conormm/r-to-python-data-wrangling-basics.md
R to Python: Data wrangling with dplyr and pandas

R to python data wrangling snippets

The dplyr package in R makes data wrangling significantly easier. The beauty of dplyr is that, by design, the options available are limited. Specifically, a set of key verbs form the core of the package. Using these verbs you can solve a wide range of data problems effectively in a shorter timeframe. Whilse transitioning to Python I have greatly missed the ease with which I can think through and solve problems using dplyr in R. The purpose of this document is to demonstrate how to execute the key dplyr verbs when manipulating data using Python (with the pandas package).

dplyr is organised around six key verbs:

@ochoto
ochoto / angr.py
Created April 2, 2019 12:23
Crackme solve for GE13 H5 with angr explorer with FIND and AVOID addresses
#!/usr/bin/env python2
"""
In this challenge we are given a binary that checks an input given from stdin.
If it is correct, it will call get_flag in a separate library and print(it.)
However, we don't have the library so need to find the correct input and input
it over netcat. If it is incorrect, only 'Goodbye' is printed.
Reversing shows that the program verifies the input character by character.]
Because of the program's linear nature and reliance on verbose constraints,
angr is perfect for solving this challenge quickly. On a virtual machine
@ochoto
ochoto / RecursiveStreams.scala
Created September 24, 2012 12:06 — forked from jeffreyolchovy/RecursiveStreams.scala
Recursive Streams in Scala
import scala.math.{BigInt, BigDecimal}
object RecursiveStreams
{
// natural numbers
lazy val N: Stream[BigInt] = Stream.cons(BigInt(1), N.map(_ + 1))
// fibonacci series
lazy val fib: Stream[BigInt] = Stream.cons(BigInt(0), Stream.cons(BigInt(1), fib.zip(fib.tail).map(a => a._1 + a._2)))
@ochoto
ochoto / oracle_charset_test.sql
Created May 22, 2013 21:17
oracle charset test
NCHR(8364)
package com.tumblr.fibr.service.filter
import com.tumblr.fibr.config.FilterConfig
import com.tumblr.fibr.tsdb.{TsdbRequest, TsdbResponse}
import com.google.common.cache.{Cache, CacheBuilder}
import com.twitter.finagle.Service
import com.twitter.util.Future
import java.util.concurrent.{Callable, TimeUnit}
/**

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

Twitter公式クライアントのコンシューマキー

Twitter for iPhone

Consumer key: IQKbtAYlXLripLGPWd0HUA
Consumer secret: GgDYlkSvaPxGxC4X8liwpUoqKwwr3lCADbz8A7ADU

Twitter for Android

Consumer key: 3nVuSoBZnx6U4vzUxf5w
Consumer secret: Bcs59EFbbsdF6Sl9Ng71smgStWEGwXXKSjYvPVt7qys

Twitter for iPad

Consumer key: CjulERsDeqhhjSme66ECg

import scala.annotation.tailrec
object paresmayores extends App {
def mayoresPares(numPares: Int, lte: Int) = {
val startNum = if (lte % 2 == 0) lte else lte - 1
@tailrec
def mp(numPares: Int, start: Int, listaPares: List[Int]): List[Int] = {
if (numPares == 0)
@ochoto
ochoto / factorion.scala
Created September 24, 2012 15:45
Factorion
object factorion extends App {
lazy val N: Stream[Int] = Stream.cons(1, N.map(_ + 1))
lazy val fact: Stream[Int] = Stream.cons(1, fact.zip(N).map(a => a._1 * a._2))
val factmap = 0 to 9 map { a => a.toString -> fact(a) } toMap
def esFactorion(n: Int) = (n.toString.toList map (c => factmap.get(c.toString).get) sum) == n
val start = System.nanoTime
@ochoto
ochoto / 2bitexpand.c
Created July 28, 2012 14:02
Expand 2 bit raw to byte
#include <stdio.h>
void expand(const char c, char b[4]) {
b[0] = c & 3;
b[1] = (c >> 2) & 3;
b[2] = (c >> 4) & 3;
b[3] = (c >> 6) & 3;
}
int main(int argc,char* argv[]) {